Not very complicated but couldn’t find an easy way of getting raw interpolated data otherwise so ended up writing this yesterday. Can do beziers, b-splines and catmull-rom splines. Might come in handy for others

# ofxCurve: addon to interpolate curves from a set of control points

**ayruos**#1

This is really handy. There are other spline add-ons out there but this is the only one I can find that includes bsplines alongside catmull.

One very minor tweak; in my use I need to assess scenarios of varying control point no.s, i.e. not always compliant to 3n+1. So I’ve added the following lines to each of the curve evaluations to allow the above, it seems to work, and allows the check on the no of control points to be commented out.

In Bezier eval. for loop:

```
int j = 3*i;
int k = 3*i+1; if(k > P.size()-1) k = j;
int m = 3*i+2; if(m > P.size()-1) m = k;
int n = 3*i+3; if(n > P.size()-1) n = m;
Curve smallBez = coreBezier(P[j], P[k], P[m], P[n], steps);
```

In Bspline eval. for loop:

```
int j = i;
int k = i+1; if(k > P.size()-1) k = j;
int m = i+2; if(m > P.size()-1) m = k;
int n = i+3; if(n > P.size()-1) n = m;
glm::vec4 cx = glm::vec4(P[j].x, P[j].y, P[j].z, 1); //etc
```

In CR eval for loop:

```
int h = (i-2) % P.size(); if(h < 0) h = 0;
int j = (i-1) % P.size(); if(j < 0) j = 0;
int k = (i) % P.size(); if(k > P.size()-1) k = j;
int m = (i+1) % P.size(); if(m > P.size()-1) m = k;
int n = (i+2) % P.size(); if(n > P.size()-1) n = m;
glm::vec4 cx = glm::vec4(P[j].x, P[j].y, P[h].z, 1); //etc
```

And one other final tweak; adding the first and last control points twice for the CR curves brings the end of the curve much closer to the start and end control points. Again, might not be exact science but works for me.

S

just added a “fast-and-dirty” fork based on this @Sam_McElhinney_io suggestions. Also added an example with https://github.com/genekogan/ofxDraggable to edit points.

**ayruos**#5

Hey @moebiussurfing , this is cool! Do you want to send a pull request?

I’ll probably add in a enum to set whether to use the classic 3n + 1 version (because that’s more mathematically correct) or this implementation, letting people be able to choose with a `.setMode(CURVE_MODE_CLASSIC)`

or something, but this should probably be added anyway

hey @ayruos, i just done that. check if you like how it is… You have the pull request now. cheers

**ayruos**#7

Hey, I’ve been travelling and have been a bit busy with a few projects, thanks for this, I’ll take a look over the weekend

just catching up… I did some more tweaks on this though now can’t remember what they all were. Don’t have a GitHub but here’s a dropbox link to the ofxCurve.cpp that I now use

S

**ayruos**#9

Man, I’ve been SO terrible in terms of finding time to work on this

Ugh, let me see when I can go through @moebiussurfing and @Sam_McElhinney_io’s updates, sorry guys for being so out of loop, but life’s been busy.

Glad you all found this useful, though!