how to calculate tangent vector for each vertex ?

I have a cubic spline C. How can i calculate tangent vector of each vertex on the curve ?

This topic is not a “Opengl advanced coding” one but a “Math and algorithm” one.

Anyway, as far as I know splines are parametrized curves, you should be able to compute some derivatives easily.

Current vertex: B, its adjacent vertices: A and C.

vector U is B->A,
vector V is B->C

vector M is UxV (cross-product)

vector N = normalize(M)

Done

vector U is B->A,
vector V is B->C

vector M is UxV (cross-product)

vector N = normalize(M)

Done

> run ERROR: "tangent is needed, not normal" >

And isn’t that tangent vector at 90 degrees of the normal?
As in
vec2 T = N.yx

Hello,

if I’m not wrong the tangent vector would be simply C-B along the curve.

dj3hut1

vec2 ?? :eek:

Anyway, there is a more intelligent way to compute these tangents since to draw this spline ( defined with control points a several tangents) you have to interpolate tangents and then generate points .
vanpn just need to read theory about cubic splines.

Thanks, I’m reading it right now. ><
From the beginning, I used gluNurbs to draw the curve, but I can’t retrieve the coordinates of each vertex on the curve. So maybe I have to compute and draw it manually. Too bad!
It’s a part of my thesis and the deadline is near. >
<

The tangent vector of the curve in the point x is equal to the value of the first derivative of the curve’s equation. And evaluating the cubic spline is an elemetary computational task (just copy the formula from the wikipedia). Have fun :slight_smile:

Do u mean this formular :

()[-1 3 -3 1 ][pi-1]
Si(t)=t^3t^2t1[ 3 -6 3 0 ][pi]
(
)[-3 0 3 0 ][pi+1]
(________________)[ 1 4 1 0 ][pi+2]

This is the uniform cubic b-spline with knot vector, matrix-form, from http://en.wikipedia.org/wiki/B-spline

For example…

I have calculated and retrieved every point on the cubic spline C. I have 1st derivative of basis functions for each point too. So, if i want to get tangent vector, what do i have to do ?
Calculate dx, dy based on 1st derivatives of basis functions and then atan(dy/dx) or what ?
Please tell me!

You are in 3D space. So the cubic spline equation p(t) gives you a vector in each point t. This vector is the position. Now, the first derivative p’(t) is the tangent in t.

The dimension of the points isn’t important, because the spline interpolation defines only rules to mix four of them.

Tangents are simple too: Instead a Cubic spline the difference of two quadric splines (with one point offset)
That shader code may help:
http://lumina.sourceforge.net/Tutorials/Bezier_Surface.html

I see.
atan(dy/dx) and i got the angle. from that i can have tangent line at each point of the curve.