Catmull-Rom Spline

From Schmid.wiki
Jump to: navigation, search

Contents

Curve

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.

Orientation

To compute an orientation frame for a curve, we need three orthogonal vectors:

  • The tangent points in the direction of the curve.
  • The normal can be any vector orthogonal to the tangent.
  • The binormal must be orthogonal to both the tangent and the normal. When these are computed, we simply use 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:

  • T is the tangent at t.
  • N is the normal at t.
  • B = T x N
  • P is the value of the curve at t.

Tangents

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.

Normals

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.

Pre-Analysis

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.

Computing Normals for Any t

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)
Personal tools