# Generating control-point tangents for a Catmull-Rom spline

From Wikipedia, we have a few variations for calculating tangents when creating a spline based only on positions of control-points:

## Finite difference

$$\mathbf m_k=\frac{\mathbf p_{k+1}-\mathbf p_k}{2(t_{k+1}-t_k)}+\frac{\mathbf p_k-\mathbf p_{k-1}}{2(t_k-t_{k-1})}$$

## Cardinal

$$\mathbf m_k=(1-c)\frac{\mathbf p_{k+1}-\mathbf p_{k-1}}{t_{k+1}-t_{k-1}}$$

## Catmull–Rom

$$\mathbf m_k=\frac{\mathbf p_{k+1}-\mathbf p_{k-1}}{t_{k+1}-t_{k-1}}$$

In all cases, $\mathbf m_k$ is the tangent vector to control point $\mathbf p_k$ and $t_k$ is the parameter value $0 \leq t \leq 1$ for $\mathbf p_k$ on the spline.

The problem I have is, this method requires knowing $t_k$ to find $\mathbf m_k$. But you can't calculate $t_k$ until you know the lengths of each section of the spline, which in turn relies on knowing the tangent vectors.

Am I misunderstanding something basic, or does this chicken-and-egg situation really exist?

-
Usually, one uses things like centripetal or chord-length parametrization to generate suitable parameter values $t_k$ corresponding to your (two or three-dimensional) points $\mathbf p_k$. – J. M. Feb 2 '12 at 11:56
@J.M. OK so it is a 'real' problem requiring some approximation... I've taken the simple approach of using straight-line length between $\mathbf p_k$ & $\mathbf p_{k+1}$. If you want the points, submit your comment as an answer. – Mr. Boy Feb 3 '12 at 18:35

The $t$ values are free variables. Within certain limits, you can use whatever values you like. The simplest choice is just $t_k=k$; in other words $t_k - t_{k-1} = 1$. This doesn't work very well unless the points are fairly equi-distant from each other. Another popular choice is to use chord-lengths: $t_k - t_{k-1} = dist(P_{k-1}, P_k)$. Yet another approach is the centripedal one: $t_k - t_{k-1} = \sqrt{dist(P_{k-1}, P_k)}$