Contents |
The construction of the Catmull-Rom spline is described in detail in Verth/Bishop: Essential Mathematics for Games & Interactive Applications, and briefly described on Wikipedia.
To compute an orientation frame for a curve, we need three orthogonal vectors:
binormal = tangent x normal.
The transformation for a point t on the curve is then:
[ T_x N_x B_x P_x ] [ T_y N_y B_y P_y ] [ T_z N_z B_z P_z ] [ 0 0 0 1 ]
where:
You can compute an approximated tangent at t by computing:
T(t) = (P(t+c) - P(t-c)),
where c is a small constant value.
The tangents for a curve are well-defined, but the normals can be computed in different ways. Commonly described normal computation methods have the problem of non-continuously varying normals.
I propose a pre-analysis step to compute a series of normals for a curve, which are then used to compute normals at any value of t.
For each section of the curve, we precompute a set number of normal samples. Computing 3 samples for each section should be adequate. The pre-analysis is performed like this:
for t = 0..1
if t = 0, normal = any vector orthogonal to T(0)
else
normal = the closest vector to previousNormal that is orthogonal to T(t)
previousNormal = normal
Finding any orthogonal vector and the closest orthogonal vector is described in the article about Vector Orthogonality.
Now we have the pre-computed normals, we can use the to find a normal N for any t:
Np(t) = pre-analysed normal closest to t N(t) = the closest vector to Np(t) that is orthogonal to T(t)