Quote:> Hello...
> I have a bunch of points (say 50) in an clock wise order
representing a
> closed contour.
> I would like to fit a Bezier or B spline over it.
> Is there public domain code other than Andrew Glassner (GEMS-1) ?
I assume you're working with 2d points? Just interpolate the x and y
values seperately, using
your prefered density function (b-spline, bilinear, etc.. see
"curve(t)" below)
You can do this by defining your contour as a pair of continious
functions fx(t) and fy(t), where
0 <= t < 1 and fx(0) = fx(1) and fy(0) = fy(1).
fx could be defined as follows:
float fx(float t)
{
float fn = t*N;
int n0 = int(fn); // N = total nr of points, 50 in your example
int n1=n0+1, n2=n1+1, n3=n2+1;
fn -= floor(fn); // fractional part between current and next
point
// wrap point indices
if (n0>=N) n0-=N;
if (n1>=N) n1-=N;
if (n2>=N) n2-=N;
if (n3>=N) n3-=N;
return curve(-1-fn)*cx[n0] + curve(-fn)*cx[n0] + curve(1-fn)*cx[n2]
+ curve(2-fn)*cx[n3]; // cx[i] are your contour points.
Quote:}
And the curve(t) function defines the type of interpolation:
float curve(float t)
{
t = fabs(t);
float t2 = t*t, t3=t2*t;
// for b-spline interpolation
if (t<1.f) return 0.5f*t3 - t2 + 2.f/3.f;
if (t<2.f) return (2.f-t)*(2.f-t)*(2.f-t)/6.f;
return 0;
/*
// for bilinear itnerpolation
if (t<1.f) return 1.f-t;
return 0;
*/
Quote:}
Well, I guess you can figure out fy(t) yourself :)
Hope this helps,
Rogier "Jace / tBL"