Jump to content
Posted 06 March 2011 - 03:08 AM
Posted 06 March 2011 - 04:12 AM
Posted 06 March 2011 - 12:15 PM
Posted 06 March 2011 - 01:21 PM
Posted 08 March 2011 - 12:29 PM
The linked article does show derivatives dx/dy and dy/dx, but you're using the parametric form of the curve. Hence you need dx/dt and dy/dt. Setting in t into the both derivatives gives you the x and y components of the unnormalized tangent (which you are using as x and z components, if I understood your latest post correctly). The Frenet Frame article shows this in the section "Other expressions of the frame", where
T(t) = r'(t) / ||r'(t)||
is mentioned (the r' means the derivative dr/dt).
The T is the normalized tangent vector along the curve, the N is the normal (i.e. it is perpendicular to the curve at location t) with a relation to the curvature of the curve at location t, and B is the bi-normal (i.e. also perpendicular to the curve at t). All together, the point at location t, T, N, B define a Cartesian axis, i.e. a local co-ordinate system similar to one used for e.g. model vertices.
Assume that you have a unit-length forward vector f and a unit-length up vector u and both are perpendicular (so f . u = 0). Then you can compute a side vector s using the cross-product
s := f x u
These 3 vectors are pairwise perpendicular and all of unit length. So they build a basis, written as the column vectors (or row vectors, depending on whether you use column or row vector math) of a matrix
[ s f u ]
and you'll have the rotational part of a local space transformation. Append a position p and you have the full transformation matrix:
[ s f u p ]
If the forward vector f and the up vector u' are not perpendicular by itself, you can compute the side vector as usual but with a additional normalization
s' := f x u'
s := s' / ||s'||
and compute the actual up vector from them
u := s x f
So the question is how to get a pair of those vectors.
One way (the simple one) is to compute the forward vector as difference vector between two points on the curve that are both close to the current point p at location t0,
p := r( t0 )
d' := r( t0 + 0.05 ) - r( t0 - 0.05 )
d := d' / ||d'||
and choosing an up vector u', e.g. [ 0 1 0 ] in your case where the curve is in x-z. Then follow the steps above. Of course, picking a delta (here 0.05) is a bit of voodoo.
Another, more exact way would be to compute dx/dt and dy/dt from your curve to determine the tangent T and use it as forward vector. Choose an up vector like above and complete the matrix as usual.
The 3rd way would be to compute the 2nd derivatives as well to yield in N, and use that as side vector.
Now it's up to you to decide how precise you want the tangent to be, and whether the up vector should be global or curvature dependent or what else. Its easy to mix up the vectors in the above, so check what I wrote if you want to use it.