The algorithm: the Catmull-Rom spline

The plugin draws its curves with a centripetal Catmull-Rom spline. This page explains its principle and settings, and why the tool behaves as it does.

Principle

A Catmull-Rom spline is an interpolating curve: it goes exactly through every clicked point (unlike a Bézier curve, which only gets close to its control points).

Between two clicked points P1 and P2, the curve segment is a cubic computed from four consecutive points: the previous point P0, both ends, and the next point P3.

_images/algo_principle.png

The red segment between P1 and P2 also depends on P0 and P3: the direction of the curve at P1 and P2 is given by the neighbouring points.

This gives the properties seen in use:

  • the curve goes through every point and its direction is continuous from one segment to the next: no corner at smooth nodes;

  • the computation is local: moving or adding a point only changes the neighbouring segments. This is why, while drawing, only the last segments are dotted (see Drawing curves): they wait for the next point;

  • at the ends, a neighbour is missing: the plugin adds a virtual point very close to the end, in the continuation of the drawing;

  • a cusp node stops the spline and starts a new one: two consecutive cusp nodes therefore give a straight segment.

The tension: uniform, centripetal, chordal

Setting: Tension of the curve (0 to 1, 0.5 by default).

How it works. To compute a segment, the spline runs through its four neighbouring points with a parameter (a kind of clock) going from one to the next. The tension α sets the “time” given to each interval: the distance between the two points raised to the power α.

  • with α = 0, every interval lasts 1, long or short: the curve goes too fast through large intervals and too slowly through small ones, hence overshoots, even loops, near close points;

  • with α = 1, the time is proportional to the distance: the curve “gains momentum” on long intervals and gets rounder between distant points;

  • α = 0.5 (square root of the distance) is the compromise proven by Yuksel et al.: never a loop or a cusp inside a segment.

The tension changes neither the number of vertices nor the points the curve goes through: only the shape between the clicked points.

  • α = 0 (uniform): the original form of Catmull and Rom; it can make loops or cusps when points are very close;

  • α = 0.5 (centripetal, default): no loop or self-intersection within a segment, and the curve follows the points closely;

  • α = 1 (chordal): a more ample curve between distant points.

_images/algo_tension.png

Same points, three settings: green = 0 (uniform), red = 0.5 (centripetal), blue = 1 (chordal). The uniform curve makes a small loop near the two close points.

In practice: keep 0.5. Try a higher value (0.7 to 1) if your curves are too “tight” between distant points, a lower one if you want them to stay closer to the straight lines between the points. The change shows immediately on the shape being drawn.

Number of vertices between two points

Setting: Nodes between each pair of points (0 to 50, 10 by default).

How it works. The spline is a continuous mathematical curve; to store it in a layer, the plugin computes it at a finite number of vertices joined by small straight segments. For each curved segment between two clicked points, it evaluates the cubic at n + 2 evenly spaced values of its parameter: the two ends (the clicked points) and n intermediate vertices, n being the setting.

  • 0: only the clicked points are kept, the result is a polyline;

  • 2 to 5: angular curve, very light geometry;

  • 10 (default): visually smooth curve for points clicked at a normal distance;

  • more: smoother, but the geometry gets heavier (file size, editing time, topology computations).

The number is the same for all the segments, whatever their length: a long segment therefore looks less smooth than a short one. Straight segments (between two cusp nodes) never get intermediate vertices.

_images/nodes_low.png

2 vertices between each pair of points: angular curve.

_images/nodes_high.png

10 vertices: smooth curve.

This setting is ignored (greyed out) when a regular density is set (next section).

Vertex density

A curve is stored in the layer as a series of small straight segments. The plugin offers two ways of placing these vertices (see Settings):

  • a fixed number of vertices per segment (Nodes between each pair of points, default): simple, but a short segment gets as many vertices as a long one;

  • a regular density (Maximum distance between vertices): the vertices are regularly spread along the curve, never further apart than the given distance, whatever the length of the segments. Straight parts get no intermediate vertices.

_images/density_fixed.png

Fixed number: dense vertices on short segments, sparse on the long one.

_images/density_regular.png

Regular density: the same spacing everywhere.

The regular density is recommended for an even result, for instance for archaeological drawing.

Further reading