Hemite Spline

Interpolation

Your Progress in this Chapter

0%

4 sections

Hemite Spline

Section 3.3 of 515 min6 code examples

Hermite Interpolation

Hermite Interpolation is a method of interpolating data points that accounts for not only the values of the function but also the values of its derivatives. While standard linear or polynomial interpolation only ensures the curve passes through the points (xi,yi)(x_i, y_i). Hermite interpolation ensures the curve matches the "slope"(tangent) at those points as well. This results in a much smoother and more physically realistic transition between points, particularly in motion planning or structural deflection models where velocity or tangency must be continuous.

1. The Cubic Hermite Spline

The most common form is the Cubic Hermite Spline. For a single interval between x0x_0 and x1x_1 the interpolant is a third-degree polynomial.To construct it, we need four pieces of information: The starting and ending values: y0y_0 and y1y_1 The starting and ending derivatives (slopes): y0′y'_0 and y1′y'_1

The resulting curve is expressed using Hermite Basis Functions, which act as weights for the coordinates and the slopes.

Example 1C#

1
2
3
4
5
6
7
8
9
10
Code is ready to run
OutputFrom the book
hermite_modes.png

2. Implementation in SepalSolver

In SepalSolver, Hermite interpolation is often used when the user provides a "slope vector" alongside their dataset. This is common in trajectory generation where you know where a robot should be and how fast it should be moving at that specific moment.

Example 2C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Code is ready to run
OutputFrom the book
Smooth transition value: 5

Examples

.. Admonition:: Example 1 : Compare Linear and Hermite interpolation for sparsely compited sin(x)

If sin(x) is give at 7 points between 00 and π\pi. Interpolate for sin(x) for 100 points between 00 and π\pi using linear and hermite spline and compare the plots.

Example 3C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Code is ready to run
OutputFrom the book
hermite_vs_linear.png

.. Admonition:: Example 2 :

If a robot moves from point A to point B, a linear path causes an abrupt change in velocity at the corners. By using Hermite interpolation and specifying the desired entry/exit velocity vectors, we create a path that the robot can follow without stopping or jerking.

Example 4C#

1
2
3
Code is ready to run

Key Difference: Hermite vs. Cubic Spline

FeatureHermite InterpolationCubic Spline
Input RequirementsRequires yy and y′y' (slopes)Requires only yy
Local ControlChanging one slope only affects the two adjacent segmentsChanging one point can affect the entire curve
ComplexityMathematically simpler (local calculation)Requires solving a system of equations (global)

Exercise: Animation of Slope Impact

Task: Observe how changing the slope dydy at the first point affects the plot of the function.

Example 5C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Code is ready to run

</example 4>

.. Admonition:: Example 5 : Using Hermite Spline as Sin Approximator

Lets use table of Sine and Cosine at 15 degrees interval given in table

Angle (°)Sine (sin⁡\sin)Cosine (cos⁡\cos)
0°0011
15°6−24\cfrac{\sqrt{6} - \sqrt{2}}{4}6+24\cfrac{\sqrt{6} + \sqrt{2}}{4}
30°12\cfrac{1}{2}32\cfrac{\sqrt{3}}{2}
45°22\cfrac{\sqrt{2}}{2}22\cfrac{\sqrt{2}}{2}
60°32\cfrac{\sqrt{3}}{2}12\cfrac{1}{2}
75°6+24\cfrac{\sqrt{6} + \sqrt{2}}{4}6−24\cfrac{\sqrt{6} - \sqrt{2}}{4}
90°1100

Example 6C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Code is ready to run
OutputFrom the book
  Angle  |  Sineapprox  |    Sine
---------+--------------+-------------
  38.66  |   0.624755   |  0.624762
  31.20  |   0.517998   |  0.517998
  74.74  |   0.964735   |  0.964735
  35.07  |   0.574501   |  0.574507
  35.91  |   0.586494   |  0.586500
  74.93  |   0.965631   |  0.965631
  71.45  |   0.948014   |  0.948020
  81.84  |   0.989870   |  0.989882
  13.01  |   0.225130   |  0.225131
  49.30  |   0.758148   |  0.758155
  64.10  |   0.899534   |  0.899541
  42.08  |   0.670135   |  0.670138
  35.39  |   0.579114   |  0.579120
  50.41  |   0.770582   |  0.770590
  73.23  |   0.957489   |  0.957491
  57.68  |   0.845030   |  0.845033
  67.52  |   0.924027   |  0.924039
  65.86  |   0.912567   |  0.912577
  89.95  |   1.000000   |  1.000000
  26.69  |   0.449116   |  0.449119
Takes a free account.