## Degrafa Cardinal Spline

The Degrafa Cardinal spline is now available from the Origin branch. Usage is very similar to the Catmull-Rom spline with the exception of the tension parameter. The Cardinal spline is based on the C-R code base, so it supports closure. The algorithm is the same as the C-R spline, so it is best used for tensions in the [0,1] range. For example,

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”

xmlns:comp=”components.*”

xmlns:degrafa=”com.degrafa.*”

xmlns:paint=”com.degrafa.paint.*”

xmlns:geom=”com.degrafa.geometry.*”

xmlns:splines=”com.degrafa.geometry.splines.*”

layout=”absolute”

width=”600″ height=”500″

pageTitle=”Cardinal Spline”

applicationComplete=”test()” viewSourceURL=”srcview/index.html”>

.

.

.

<paint:SolidStroke id=”redstroke” weight=”2″ color=”#FF0000″/>

<splines:CardinalSpline id=”crspline” graphicsTarget=”{[splineLayer1]}” stroke=”{redstroke}” knots=”453,159 350,302 218,202 146,297 400,110″ tension=”0″ closed=”true” />

produces the same fit as the Catmull-Rom spline,

Changing the tension to 1 ‘pulls’ the spline to the point where the fit is line-to-line,

<splines:CardinalSpline id=”crspline” graphicsTarget=”{[splineLayer1]}” stroke=”{redstroke}” knots=”453,159 350,302 218,202 146,297 400,110″ tension=”1″ closed=”true” />

Tensions in the range -1 to 3 are supported. Negative tension ‘loosens’ the fit. Tensions greater than 1 cause the spline to loop in on itself going into and out of each knot. The effect at initial and terminal knots depends on how the auxiliary control points are chosen (same options as the C-R spline).

Splines are open by default. For example,

<splines:CardinalSpline id=”crspline” graphicsTarget=”{[splineLayer1]}” stroke=”{redstroke}” knots=”453,159 350,302 218,202 146,297 400,110″ tension=”-0.5″ />

produces the following

I’m preparing for a long business trip, so posts and Degrafa updates will be sparse over the next several weeks.

## Cardinal Splines Part 4

Continuing from part 3 of this series, a formal tension parameter, T = 1-2s, was introduced. All we noted about tension was that T=0 corresponds to s = 1/2. At s=1/2, the Cardinal spline takes on the form of the more familiar Catmull-Rom spline. The Catmull-Rom spline may, however, be derived independently from the notion of Cardinal splines as the blending of two parabolas [1]. The zero-tension Cardinal Spline happens to conforms to a well-known C-1 continuous spline.

What happens as the tension parameter is moved away from zero? Can it reasonably be both positive and negative? To better understand the effect of the tension parameter on the spline, the Cardinal-spline basis matrix is

[ -s 2-s s-2 s ] [ 2s s-3 3-2s -s ] [ -s 0 s 0 ] [ 0 1 0 0 ]

Given four arbitrary knots,

[P_{1}, P_{2}, P_{3}, P_{4}]

the following vector equation applies for an aribrary point P(t) on the curve from P_{2} to P_{3}

P(t) = s(-t^{3} + 2t^{2} – t)P_{1} + s(-t^{3} + t^{2})P_{2} + (2t^{3} – 3t^{2} + 1)P_{2} + s(t^{3} – 2t^{2} + t)P_{3} + (-2t^{3} + 3t^{2})P_{3} + s(t^{3} – t^{2})P_{4}

We have already looked at T = 0, so consider T = 1, corresponding to s = 0. The equation for P(t) reduces to

(2t^{3} – 3t^{2} + 1)P_{2} + (-2t^{3} + 3t^{2})P_{3}, which can be simplified to

(3t^{2} – 2t^{3})(P_{3} – P_{2}) + P_{2}. If u = 3t^{2} – 2t^{3}, then

P(t) = (1-u)P_{2} + uP_{3}, which is the parametric equation of a line from P_{2} to P_{3}.

While u does vary from 0 to 1, the primary curve parameter is t. At t varies from 0 to 1, u is approximately sigmoid but very close to linear throughout its range. So, we can say that as T approaches 1, the spline approaches a straight-line interpolation between knots.

The following screenshot shows a four-knot example with a black line connecting the knots and the spline drawn in blue with T=1. The Degrafa Catmull-Rom spline is drawn in red, which corresponds to the Cardinal spline with zero tension. This allows a comparison of the range of fits available in the tension range from zero to one.

The natural tension range is from zero to one. Values outside this range are possible, although rarely practical. These factors are discussed in the next section of this series.

References:

[1] Salomon, D. “Computer Graphics and Geometric Modeling”, Springer Verlag, NY, 1999.

## Cardinal Splines Part 3

Continuing from part 2 of this series, the tension in a Cardinal spline is controlled by the s-parameter. Given a four-tuple of control points or knots,

[P_{a}, P_{b}, P_{c}, P_{d}]

cubic Hermite interpolation is applied with start-tangent s(P_{c} – P_{a}) and end-tangent s(P_{d} – P_{b}) .

Theoretically, s could vary from zero to positive infinity. A very long tangent vector, indicated by a large s-value causes the curve to follow the tangent very closely in and out of the join point. A very small tangent vector, indicated by a small s-value, causes the curve to approach and leave the join point more like a straight line.

Intuitively, this is the opposite of how we expect tension to behave. Larger tension should ‘pull’ the curve closer to a straight-line interpolation of the knots, with exactly straight lines as a limiting case. This gives rise to the convention of a formal tension parameter, T, that is inversely related to s.

The typical convention is to define s = (1-T)/2 or T = 1 – 2s. Note that the zero-tension case corresponds to s = 1/2 or a relatively ‘loose’ movement into and out of each join. This special case corresponds to the Catmull-Rom spline. For this reason, the C-R spline is sometimes called the zero-tension or neutral Cardinal spline.

The tension parameter will be discussed in more detail in subsequent posts in this series. Tangent vectors are arbitrary at the initial and terminal knots, just as with the Catmull-Rom spline. Fortunately, there are several methods for automatically assigning these tangents. The C-R spline in Degrafa implements two methods; point duplication and point reflection. Line segment reflection can be added as a third option. It is also possible to allow designers to set these tangents interactively.

Local control via knot placement, tension control, and adjustment of initial/terminal tangent vectors provides artists with a variety of methods to design specific curves using Cardinal splines.