Damn, this is boring. Bring me back to the Code-Corner!
Table Of Contents
Hermite curves are very easy to calculate but very powerfull to use.
They are used to smoothly interpolate data between key-points (like object
movement in keyframe animation or camera control). Understanding the
mathematical background of hermite curves will help you to understand
the entire family of splines.
Maybe you have some experiences with 3D programming and already used them
without knowing that.. (the so called kb-splines, curves with control over
tension, continuity and bias are just a special form of the hermite curves).
To keep it simple we first start with some simple stuff. We also only
talk about 2 dimensional curves here. If you need a 3d curve just do the same
with the z-coordinate what you did with y or x. Hermite curves work in
in any dimension.
To calculate a hermite curve you need the following vectors:

h1(s) = 2s^3 - 3s^2 + 1 h2(s) = -2s^3 + 3s^2 h3(s) = s^3 - 2s^2 + s h4(s) = s^3 - s^2Below are the 4 graphs of the 4 functions (from left to right: h1, h2, h3, h4)

h3 and h4 are applied to the tangents in the same manner.
They take care, that the curve bends into the desired direction at the start and endpoint.
All this stuff can be expessed with some vector and matrix algebra.
I think the matrix-form is much better to understand.
Vector S: The interpolation-point and it's powers up to 3:
Vector C: The parameters of our hermite curve:
Matrix h: The matrix form of the 4 hermite polyonials:
| s^3 | | P1 | | 2 -2 1 1 |
S = | s^2 | C = | P2 | h = | -3 3 -2 -1 |
| s^1 | | T1 | | 0 0 1 0 |
| 1 | | T2 | | 1 0 0 0 |
To calculate a point on the curve you build the Vector S,
multiply it with the matrix h and the again multiply with C.
P = S * h * C
A little side-note: Bezier-Curves
This matrix-form is valid for all cubic polynomial curves.. The only
thing that changes is the polynomial matrix.. For example if you want to
draw a Bezier curve instead of hermites you might use this matrix:
| -1 3 -3 1 |
b = | 3 -6 3 0 |
| -3 3 0 0 |
| 1 0 0 0 |
Sure, this C-style pseudo-code won't compile.. C doesn't come with a
power function, and unless you wrote yourself a vector-class any compiler
would generate hundrets of erros and make you feel like an idiot.
I think it's better to present this code in a more abstract form.
moveto (P1); // move pen to startpoint
for (int t=0; t < steps; t++)
{
float s = (float)t / (float)steps; // scale s to go from 0 to 1
float h1 = 2s^3 - 3s^2 + 1; // calculate basis function 1
float h2 = -2s^3 + 3s^2; // calculate basis function 2
float h3 = s^3 - 2*s^2 + s; // calculate basis function 3
float h4 = s^3 - s^2; // calculate basis function 4
vector p = h1*P1 + // multiply and sum all funtions
h2*P2 + // together to build the interpolated
h3*T1 + // point along the curve.
h4*T2;
lineto (p) // draw to calculated point on the curve
}
I know.. controlling the Tangents is not easy.. It's hard to guess how a
curve will look like if you have to define it.
Also, to making a sharp bended curve you have to drag the tangent-points far from the curve.
I'll know show you how you can turn the hermite curves into cardinal splines:
The formula for the tangents for cardinal splines is:
T = a * ( P - P )
i i+1 i-1
a is a constant which affects the tightness of the curve.
T = 0.5 * ( P - P )
i i+1 i-1
Easy, isn't it? Take a math-book and look for Catmull-Rom splines Try to
understand how they work!.
The "incomming" Tangent equation:
(1-t)*(1-c)*(1+b)
TS = ----------------- * ( P - P )
i 2 i i-1
(1-t)*(1+c)*(1-b)
+ ----------------- * ( P - P )
2 i+1 i
The "outgoing" Tangent equation:
(1-t)*(1+c)*(1+b)
TD = ----------------- * ( P - P )
i 2 i i-1
(1-t)*(1-c)*(1-b)
+ ----------------- * ( P - P )
2 i+1 i
When you want to interpolate the curve you should use this vector:
| P(i) |
C = | P(i+1) |
| TD(i) |
| TS(i+1) |
You might notice, that you always need the previous and following point
if you want to calculate the curve. This might be a problem when you try
to calculate keyframe data from lightwave or 3D-Studio. I don't exactly
know how these programs handle the cases of the first and last point, but
there are enough sources available on the internet. Just search around
a little bit. (Newtek has a good developer section. You can download
the origignal lightwave motion code on their web-site).
Speed Control
If you write yourself a keyframe-interpolation code and put it into a program
you'll notice one problem:
Unless you have your keyframes in fixed intervals you will have a sudden change
of speed and direction whenever you pass a keyframe-point.
This can be avoided if you take the number of key-positions (frames) between two keyframes into account:
N is the number of frames (seconds, whatever) between two keypoints.
2 * N
i-1
TD = TD * --------------- adjustment of outgoing tangent
i i N + N
i-1 i
2 * N
i
TS = TS * --------------- adjustment of incomming tangent
i i N + N
i-1 i
Why does noone care, that's almost impossible to do nice formated math-formulas
in HTHL?
What's more imporant? A good design or a good content?
As always you might want to contact me: This is my email: Submissive@cubic.org