This page was generated from doc/euclidean/natural-properties.ipynb. Interactive online version: Binder badge.

Properties of Natural Splines#

The most important property of (cubic) natural splines is that they are \(C^2\) continuous, which means that the second derivatives match at the transitions between segments. On top of that, they are interpolating, which means that the curve passes through the given control points.

[1]:
import splines
import matplotlib.pyplot as plt
[2]:
vertices = [
    (0, 0),
    (1, 1),
    (1.5, 1),
    (1.5, -0.5),
    (3.5, 0),
    (3, 1),
    (2, 0.5),
    (0.5, -0.5),
]

To show an example, we use the class splines.Natural and a plotting function from helper.py:

[3]:
from helper import plot_spline_2d
[4]:
plot_spline_2d(
    splines.Natural(vertices, endconditions='closed'),
    chords=False)
../_images/euclidean_natural-properties_6_0.svg

A downside of natural splines is that they don’t provide local control. Changing only a single control point potentially influences the whole curve.

[5]:
modified_vertices = vertices.copy()
modified_vertices[6] = 1, 0.5
[6]:
plot_spline_2d(
    splines.Natural(vertices, endconditions='closed'),
    chords=False)
plot_spline_2d(
    splines.Natural(modified_vertices, endconditions='closed'),
    chords=False)
../_images/euclidean_natural-properties_9_0.svg

We can see that there are deviations in all segments, not only close to the modified vertex.

For comparison, we can use the same vertices to create a uniform cubic Catmull–Rom spline using the splines.CatmullRom class:

[7]:
plot_spline_2d(
    splines.CatmullRom(vertices, endconditions='closed'),
    chords=False)
plot_spline_2d(
    splines.CatmullRom(modified_vertices, endconditions='closed'),
    chords=False)
../_images/euclidean_natural-properties_11_0.svg

Here we can see that two segments before and two segments after the modified vertex are affected, but the rest of the segments remain unchanged.

Although this is typically only used with Catmull–Rom splines, we can also use centripetal parameterization for a natural spline:

[8]:
plot_spline_2d(
    splines.Natural(vertices, endconditions='closed'),
    chords=False, label='uniform')
plot_spline_2d(
    splines.Natural(vertices, endconditions='closed', alpha=0.5),
    chords=False, label='centripetal')
plt.legend(numpoints=3);
../_images/euclidean_natural-properties_14_0.svg