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

Properties of Hermite Splines#

Hermite splines are interpolating polynomial splines, where for each polynomial segment the desired value at the start and end is given (obviously!), as well as the values of a certain number of derivatives at the start and/or the end.

Most commonly, cubic (= degree 3) Hermite splines are used. Cubic polynomials have 4 coefficients to be chosen freely, and those are determined for each segment of a cubic Hermite spline by providing 4 pieces of information: the function value and the first derivative, both at the beginning and the end of the segment.

Other degrees of Hermite splines are possible (but much rarer), for example quintic (= degree 5) Hermite splines, which are defined by the second derivatives at the start and end of each segment, on top of the first derivatives and the function values (6 values in total).

Hermite splines with even degrees are probably still rarer. For example, quadratic (= degree 2) Hermite splines can be constructed by providing the function values at both beginning and end of each segment, but only one first derivative, either at the beginning or at the end (leading to 3 values in total). Make sure not to confuse them with quartic (= degree 4) Hermite splines, which are defined by 5 values per segment: function value and first derivative at both ends, and one of the second derivatives.

However, cubic Hermite splines are so overwhelmingly common that they are often simply referred to as Hermite splines. From this point forward, we will only be considering cubic Hermite splines.

[1]:
import splines
[2]:
import matplotlib.pyplot as plt
import numpy as np

We import a few helper functions from helper.py:

[3]:
from helper import plot_spline_1d, plot_slopes_1d, grid_lines
from helper import plot_spline_2d, plot_tangents_2d

Let’s look at a one-dimensional spline first. Here are some values (to be interpolated) and a list of associated parameter values (or time instances, if you will).

[4]:
values = 2, 4, 3, 3
grid = 5, 7, 8, 10

Since (cubic) Hermite splines ask for the first derivative at the beginning and end of each segment, we have to come up with a list of slopes (outgoing, incoming, outgoing, incoming, …).

[5]:
slopes = 0, 0, -1, 0.5, 1, 3

We are using the splines.CubicHermite class to create the spline:

[6]:
s1 = splines.CubicHermite(values, slopes, grid=grid)

OK, let’s plot this one-dimensional spline, together with the given values and slopes.

[7]:
plot_spline_1d(s1)
plot_slopes_1d(slopes, values, grid)
grid_lines(grid)
../_images/euclidean_hermite-properties_14_0.svg

Let’s try a two-dimensional curve now (higher dimensions work similarly).

[8]:
vertices = [
    (0, 0),
    (2, 0),
    (1, 1),
]

The derivative of a curve is its tangent vector, so here is a list of associated tangent vectors (outgoing, incoming, outgoing, incoming, …):

[9]:
tangents = [
    (2, 1),
    (0.1, 0.1),
    (-0.5, 1),
    (1, 0),
]
[10]:
s2 = splines.CubicHermite(vertices, tangents)
[11]:
fig, ax = plt.subplots()
plot_spline_2d(s2, ax=ax)
plot_tangents_2d(tangents, vertices, ax=ax)
../_images/euclidean_hermite-properties_20_0.svg

If no parameter values are given (by means of the grid argument), the splines.CubicHermite class creates a uniform spline, i.e. all parameter intervals are automatically chosen to be 1. We can create a non-uniform spline by providing our own parameter values:

[12]:
grid = 0, 0.5, 3

Using the same vertices and tangents, we can clearly see how the new parameter values influence the shape and the speed of the curve (the dots are plotted at equal time intervals!):

[13]:
s3 = splines.CubicHermite(vertices, tangents, grid=grid)
[14]:
plot_spline_2d(s3, ax=ax)
fig
[14]:
../_images/euclidean_hermite-properties_25_0.svg
../_images/euclidean_hermite-properties_25_1.svg

Hermite splines are by default \(C^0\) continuous. If adjacent tangents are chosen to point into the same direction, the spline becomes \(G^1\) continuous. If on top of having the same direction, adjacent tangents are chosen to have the same length, that makes the spline \(C^1\) continuous. An example for that are Catmull–Rom splines. Kochanek–Bartels splines can also be \(C^1\) continuous, but only if their “continuity” parameter \(C\) is zero.

There is one unique choice of all of a cubic Hermite spline’s tangents – given certain end conditions – that leads to continuous second derivatives at all vertices, making the spline \(C^2\) continuous. This is what natural splines are all about.