3

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)). Tangent generated by drawing a line between (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)

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.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
sss999
  • 528
  • 3
  • 14

1 Answers1

5

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).

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
  • So same has to be done for drawing normal too then right? I mean drawing a line between P(t) and P(t)+normal(t) – sss999 Sep 30 '16 at 19:15
  • 1
    @sss999: Essentially yes. Note that instead of making the tangent/normal/whatever proportional to their velocity/curvature/whatever, you can always choose to draw them of fixed size by normalizing the vector. E.g. `P(t) + P'(t)/|P'(t)|` for tangent. `normal` is probably already normalized. – Yakov Galka Sep 30 '16 at 19:19
  • Note that for 3D, things are a little bit more work because you need to find the plane of travel for points on the curve first, but it's not *super* complicated, and covered in http://stackoverflow.com/a/25458216/740553 – Mike 'Pomax' Kamermans Oct 04 '16 at 14:27