   [BEZIER] again, derivate of a bezier curve
  hithis is my first post in forumi'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 codeArrayList<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.jpgok. 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.jpgand 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.htmlps.sorry for my bad english[Edited by - nkint on April 11, 2010 11:27:17 AM]
  I think you got an off-by-one-bug here:for (int i=0; i<degree-1; i++) {...According to your reference the summation goes from 0 to n-1 inclusive. So:for (int i=0; i<=degree-1; i++) {...Hope that helps   ;  thanks for answer but noit is not that errorthe tangent has the same wrong direction..   ;  Ok, there's another one. The bernstein factor was wrong and is the same for both points, so    for (int i = 0; i <= degree - 1; i++)    {   b = Bernstein.compute(t, i, degree);    // == B i,n (t)   p1 = controlPoints.get(i + 1);// == P i + 1   x1 += b * p1.x;// summation   y1 += b * p1.y;   z1 += b * p1.z;   p2 = controlPoints.get(i);    // == P i    x2 += b * p2.x;// summation   y2 += b * p2.y;   z2 += b * p2.z;    }Now it should work.Quote:or, better, i can't manage to figure how write in code mathematical expressionNot having operator overloading at hand makes it difficult to find bugs. One hint though: If your formulas get complex explain steps with comments (s. above) and use similar variable names to get less confused (e.g. u instead of t here) until it's working. Afterwards you can always rename them.   