I currently have a Bezier curve being generated by adding certain Bezier curves of degree 4 together. I am using GL_LINES
. I need to draw a tangent, normal and binormal at each of the Bezier points.
As far as I know, to find a tangent at any given value of t, the equation is
P'(t) = 4 * (1-t)^3 *(P1 - P0) + 12 *(1-t)^2*t*(P2-P1) + 12 * (1-t) * t^2 * (P3-P2) + 4 * t^3 * (P4-P3)
I am currently using the above equation in the following way.
temp = 1-t;
tangentPoints[val].XYZW[j] = (4 * pow(temp, 3)*(V[k + 1].XYZW[j] - V[k].XYZW[j])) + (12 * pow(temp, 2)*t*(V[k + 2].XYZW[j] - V[k + 1].XYZW[j])) + (12 * (temp)*pow(t, 2)*(V[k + 3].XYZW[j] - V[k + 2].XYZW[j])) + (4 * pow(t, 3)*(V[k + 4].XYZW[j] - V[k + 3].XYZW[j]));
where j corresponds to x,y,z values and tangentPoints
is a structure defined by me for the vertices. V is an array of vertices of the control points.
I am simply drawing a line between the point on the Bezier curve (say x) for a value t and its corresponding tangent value (say dx)
However while drawing the tangents between (x, dx), I get something like this (drawing a line from (x,dx)).
But when I am adding the Bezier point to each of the corresponding tangent points, I am getting the right image, i.e., I am getting the correct result by drawing a line between (x,x+dx)
Can anyone tell me why is this so and also provide an insight of drawing a tangent and normal to a given Bezier point.