Reputation: 528
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.
Upvotes: 3
Views: 1480
Reputation: 72469
Though P'(t)
is sometimes called the tangent, it is actually the derivative of the curve, aka the velocity. If the curve is in the 2d space and its points are measured in meters, say, then the units of P'(t)
will be in meters/second. It does not make sense to draw a line between '5 meters' and '6 meters/second' because they are points in different spaces.
What you should do is to draw a line between 'the point on the curve' and 'where the object would be if it was detached from the curve and continued to move at its current velocity for 1 second'. That is between P(t)
and P(t) + dt * P'(t)
.
Upvotes: 5