Interpolation

Your Progress in this Chapter

0%

0 / 10 units completed

Chapter Overview

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 (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 x_0 and x_1 the interpolant is a third-degree polynomial.To construct it, we need four pieces of information: The starting and ending values: y_0 and y_1 The starting and ending derivatives (slopes): y'_0 and 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 0 and \pi. Interpolate for sin(x) for 100 points between 0 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 y and y' (slopes)Requires only y
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 dy 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)Cosine (\cos)
01
15°\cfrac{\sqrt{6} - \sqrt{2}}{4}\cfrac{\sqrt{6} + \sqrt{2}}{4}
30°\cfrac{1}{2}\cfrac{\sqrt{3}}{2}
45°\cfrac{\sqrt{2}}{2}\cfrac{\sqrt{2}}{2}
60°\cfrac{\sqrt{3}}{2}\cfrac{1}{2}
75°\cfrac{\sqrt{6} + \sqrt{2}}{4}\cfrac{\sqrt{6} - \sqrt{2}}{4}
90°10

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
---------+--------------+-------------
  22.47  |   0.382216   |  0.382220
  49.22  |   0.757171   |  0.757178
  34.61  |   0.568044   |  0.568049
  39.39  |   0.634616   |  0.634623
  76.86  |   0.973822   |  0.973824
  81.41  |   0.988768   |  0.988780
  80.35  |   0.985833   |  0.985843
  19.16  |   0.328197   |  0.328200
  12.59  |   0.217959   |  0.217960
  38.53  |   0.622888   |  0.622895
  42.79  |   0.679328   |  0.679330
  20.26  |   0.346344   |  0.346347
  22.28  |   0.379171   |  0.379176
  25.29  |   0.427126   |  0.427129
  47.94  |   0.742429   |  0.742432
  64.80  |   0.904815   |  0.904823
  23.18  |   0.393599   |  0.393604
  31.18  |   0.517792   |  0.517793
  17.09  |   0.293856   |  0.293857
  43.92  |   0.693713   |  0.693713