PDA

View Full Version : how to calculate tangent vector for each vertex ?

vanpn
07-16-2008, 11:27 PM
I have a cubic spline C. How can i calculate tangent vector of each vertex on the curve ?

dletozeun
07-17-2008, 01:18 AM
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.

Ilian Dinev
07-17-2008, 12:56 PM
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

dletozeun
07-17-2008, 01:25 PM
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"
\$>

Ilian Dinev
07-17-2008, 03:25 PM
And isn't that tangent vector at 90 degrees of the normal?
As in
vec2 T = N.yx

Dj3hut1
07-18-2008, 01:02 AM
Hello,

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

dj3hut1

dletozeun
07-18-2008, 01:35 AM
And isn't that tangent vector at 90 degrees of the normal?
As in
vec2 T = N.yx

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
07-20-2008, 06:30 AM
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. >_<

Zengar
07-20-2008, 08:45 AM
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 :)

vanpn
07-21-2008, 12:07 AM
Do u mean this formular :

(________________)[-1 3 -3 1 ][pi-1]
Si(t)=[t^3t^2t1](1/6)[ 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

Zengar
07-21-2008, 04:30 AM
For example...

vanpn
07-25-2008, 08:49 AM
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 ?

Zengar
07-25-2008, 09:15 AM
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.

oc2k1
07-25-2008, 08:13 PM
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)