hi
this is my first post in forum
i've tried to find a post about derivate of a bezier curve but i din't manage to undestrand at all.
i'm creating a bezier curve in java using this methos:
//java code
ArrayList<Point3D> controlPoints;
...
public Point3D samplePoint(float t) {
float b,
x = 0,
y = 0,
z = 0;
for (int i=0; i<=degree; i++) {
b = Bernstein.compute(t, i, degree);
x += (controlPoints.get(i).x)*b;
y += (controlPoints.get(i).y)*b;
z += (controlPoints.get(i).z)*b;
}
return new Point3D(x,y,z);
}
i think this is casteljeau algorithm that use bernstein polynomials.
it runs perfectly.
i think is this one:
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/b-eqn.jpg
ok. now i want to fine the 1° and 2° derivate
for tangent, binormal, normal.
for first derivate i try to follow this:
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/b-derv-1.jpg
and code is:
public static Vector3D sampleDerivateI(float t) {
/*
* First derivate in Bezier with casteljeau algorithm
* the first curve C1(u) is defined by control points P1, P2, ..., Pn
* the second curve C2(u) is defined by control points P0, P1, ..., Pn-1
* C'(u) = n(C1(u) - c2(u))
*
*/
float
x1 = 0,
y1 = 0,
z1 = 0,
b1, b2;
float
x2 = 0,
y2 = 0,
z2 = 0;
Point3D p1, p2;
for (int i=0; i<degree-1; i++) {
q = deltaPoint(i, t);
b1 = Bernstein.compute(t, i+1, degree-1);
p1 = controlPoints.get(i+1);
x1 += b1*p1.x;
y1 += b1*p1.y;
z1 += b1*p1.z;
b2 = Bernstein.compute(t, i, degree-1);
p2 = controlPoints.get(i);
x2 += b2*p2.x;
y2 += b2*p2.y;
z2 += b2*p2.z;
}
return new Vector3D(degree*(x1-x2), degree*(y1-y2), degree*(z1-z2));
}
It compile but it do not seems to be a derivate.
I tryed to find others solutions in iternet but no one works good
(or, better, i can't manage to figure how write in code mathematical expression)
please, i don't know how to do it!!
reference:
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-der.html
ps.
sorry for my bad english
[Edited by - nkint on April 11, 2010 11:27:17 AM]