Assignment 4 Research Methodology 2
Assignment 4
Course Name: Research Methodology 2 (MTech-PhD and PhD Students)
Course Coordinator: Dr. Pavan Chakraborty
Topic Name: SPLINE Blending Function Hermite and Basier Assignment
Date (Lecture): 21-11-2024
Submitted by: Agrim Ray (PNS2024003)
Question
Suppose two points Pi and Pi+1 are fitted with a cubic function P (u) = a3 u3 + a2 u2 +
a1 u + a0 , where the parameter u takes values at Pi when u = 0 and at Pi+1 when u = 1.
′
Given the values Pi , Pi+1 , and their derivatives Pi′ and Pi+1 , determine the coefficients
a3 , a2 , a1 , and a0 . This can be expressed in matrix form as:
T
Pi
3 2 Pi+1
u u u 1 · {H} ·
Pi′
′
Pi+1
where {H} is the matrix of the Hermite blending functions. Next, determine the four
Hermite blending functions [u3 , u2 , u, 1] · {H}, and plot them. If we multiply all the four
Hermite blending functions by 2.05 and add them, what curve is obtained? For the Bezier
spline, take Pi′ = 3(Pi − Pi−1 ) and Pi+1 ′
= 3(Pi+2 − Pi+1 ). Use the matrix method to
derive the Bezier spline.
Then, determine the four Bezier blending functions [u3 , u2 , u, 1] · {B}, and plot them.
If we multiply all the four Bezier blending functions by 2.05 and add them, what curve
is obtained?
Answer
Cubic Hermite Interpolation
Let the general cubic polynomial be:
P (u) = a3 u3 + a2 u2 + a1 u + a0
Step 1: Conditions at endpoints The cubic Hermite interpolation satisfies the
following constraints:
1. P (0) = Pi : the curve passes through the first point.
2. P (1) = Pi+1 : the curve passes through the second point.
3. P ′ (0) = Pi′ : the slope at the first point is Pi′ .
Page 1 PNS2024003
Assignment 4 Research Methodology 2
4. P ′ (1) = Pi+1
′ ′
: the slope at the second point is Pi+1 .
These conditions define the behavior of the cubic polynomial P (u) at the endpoints.
—
Step 2: Derive the coefficients a0 , a1 , a2 , a3
At u = 0:
1. P (0) = a0 = Pi ⇒ a0 = Pi ,
2. P ′ (0) = a1 = Pi′ ⇒ a1 = Pi′ .
At u = 1:
1. P (1) = a3 + a2 + a1 + a0 = Pi+1 ,
a3 + a2 + Pi′ + Pi = Pi+1 ,
a3 + a2 = Pi+1 − Pi − Pi′ .
2. P ′ (1) = 3a3 + 2a2 + a1 = Pi+1
′
,
′ ′
3a3 + 2a2 + Pi = Pi+1 ,
′
3a3 + 2a2 = Pi+1 − Pi′ .
—
Step 3: Solve for a3 and a2 We now solve the system of equations:
a3 + a2 = Pi+1 − Pi − Pi′ ,
′
3a3 + 2a2 = Pi+1 − Pi′ .
Solve for a3 : From the first equation:
a2 = Pi+1 − Pi − Pi′ − a3 .
Substitute into the second equation:
3a3 + 2(Pi+1 − Pi − Pi′ − a3 ) = Pi+1
′
− Pi′ ,
3a3 + 2Pi+1 − 2Pi − 2Pi′ − 2a3 = Pi+1
′
− Pi′ ,
a3 = 2(Pi+1 − Pi ) + Pi′ − Pi+1
′
.
Solve for a2 : Substitute a3 back into the first equation:
a2 = Pi+1 − Pi − Pi′ − 2(Pi+1 − Pi ) + Pi′ − Pi+1
′
,
a2 = −3Pi − 2Pi′ + 3Pi+1 − Pi+1
′
.
—
Step 4: Write the coefficients The coefficients are:
a0 = P i ,
a1 = Pi′ ,
a2 = −3Pi − 2Pi′ + 3Pi+1 − Pi+1
′
,
a3 = 2Pi + Pi′ − 2Pi+1 + Pi+1
′
.
Page 2 PNS2024003
Assignment 4 Research Methodology 2
—
Step 5: Matrix form The cubic polynomial can be expressed in matrix form as:
a3
a2
P (u) = [u3 u2 u 1]
a1 .
a0
Substituting the coefficients into the matrix:
2 −2 1 1 Pi
−3 3 −2 −1 Pi+1
P (u) = [u3 u2 u 1] .
0 0 1 0 Pi′
′
1 0 0 0 Pi+1
—
Step 6: Hermite blending functions The Hermite blending functions are the
′
coefficients of Pi , Pi+1 , Pi′ , Pi+1 when multiplying [u3 u2 u 1] by the Hermite matrix:
h1 (u) = 2u3 − 3u2 + 1,
h2 (u) = −2u3 + 3u2 ,
h3 (u) = u3 − 2u2 + u,
h4 (u) = u3 − u2 .
These functions interpolate the positions and derivatives at the endpoints.
Hermite Blending Functions: [u3, u2, u, 1] · [H]
To determine the Hermite blending functions, we multiply the vector [u3 , u2 , u, 1] by the
Hermite matrix [H]:
2 −2 1 1
−3 3 −2 −1
H= 0
.
0 1 0
1 0 0 0
The blending functions are given by:
h1 (u)
h2 (u) 3 2
= [u u u 1] · H.
h3 (u)
h4 (u)
Python Code to Compute and Plot Blending Func-
tions
The Python code below computes the Hermite blending functions and plots them.
Page 3 PNS2024003
Assignment 4 Research Methodology 2
Listing 1: Python Code for Hermite Blending Functions
import numpy as np
import matplotlib . pyplot as plt
# Hermite coefficient matrix
H = np . array ([
[2 , -2 , 1 , 1] ,
[ -3 , 3 , -2 , -1] ,
[0 , 0 , 1 , 0] ,
[1 , 0 , 0 , 0]
])
# Define the range for u
u = np . linspace (0 , 1 , 500)
# Basis vector for [ u ^3 , u ^2 , u , 1]
U = np . array ([ u **3 , u **2 , u , np . ones_like ( u ) ])
# Calculate the blending functions
blending_f un ct io ns = np . dot ( H .T , U ) # Shape : (4 , len ( u ) )
# Plot the blending functions
plt . figure ( figsize =(8 , 6) )
for i , h in enumerate ( blending_functions , start =1) :
plt . plot (u , h , label = f " $h_ { i }( u ) $ " )
plt . title ( " Hermite Blending Functions " )
plt . xlabel ( " $u$ " )
plt . ylabel ( " $h ( u ) $ " )
plt . axhline (0 , color = " black " , linewidth =0.8 , linestyle = " --" )
plt . legend ()
plt . grid ( True )
plt . show ()
Page 4 PNS2024003
Assignment 4 Research Methodology 2
Plot of the Hermite Blending Functions
Scaling and Summing the Hermite Blending Functions
When we multiply each of the Hermite blending functions h1 (u), h2 (u), h3 (u), h4 (u) by
2.05 and sum them up, the resulting curve can be expressed as:
C(u) = 2.05 · (h1 (u) + h2 (u) + h3 (u) + h4 (u)).
Analysis of the Result
Step 1: Sum of Hermite Blending Functions The Hermite blending functions
h1 (u), h2 (u), h3 (u), h4 (u) are defined such that:
h1 (u) + h2 (u) + h3 (u) + h4 (u) = 1, ∀u ∈ [0, 1].
This property arises because the Hermite blending functions form a basis for interpo-
lating a cubic polynomial with specific conditions on the endpoints and derivatives.
Step 2: Scaling and Summing Since the sum of the blending functions is 1,
multiplying by 2.05 yields:
C(u) = 2.05 · 1 = 2.05.
Conclusion The resulting curve is a constant horizontal line at y = 2.05 across
the interval u ∈ [0, 1].
Page 5 PNS2024003
Assignment 4 Research Methodology 2
Listing 2: Python Code to Calculate and Plot the Resulting Curve
import numpy as np
import matplotlib . pyplot as plt
# Define the range for u
u = np . linspace (0 , 1 , 500)
# Hermite blending functions h1 , h2 , h3 , h4
h1 = 2* u **3 - 3* u **2 + 1
h2 = -2* u **3 + 3* u **2
h3 = u **3 - 2* u **2 + u
h4 = u **3 - u **2
# Sum of the blending functions multiplied by 2.05
result_curve = 2.05 * ( h1 + h2 + h3 + h4 )
# Hermite coefficient matrix
H = np . array ([
[2 , -2 , 1 , 1] ,
[ -3 , 3 , -2 , -1] ,
[0 , 0 , 1 , 0] ,
[1 , 0 , 0 , 0]
])
# Basis vector for [ u ^3 , u ^2 , u , 1]
U = np . array ([ u **3 , u **2 , u , np . ones_like ( u ) ])
# Calculate the blending functions
blending_f un ct io ns = np . dot ( H .T , U ) # Shape : (4 , len ( u ) )
# Plot the blending functions and resulting curve on the same
graph
plt . figure ( figsize =(8 , 6) )
# Plot individual blending functions
for i , h in enumerate ( blending_functions , start =1) :
plt . plot (u , h , label = f " $h_ { i }( u ) $ " )
# Plot the resulting curve
plt . plot (u , result_curve , label = r " $C ( u ) = 2.05 \ cdot ( h_1 ( u ) +
h_2 ( u ) + h_3 ( u ) + h_4 ( u ) ) $ " , color = ’ orange ’ , linestyle = ’ -- ’)
# Add labels , title , and legend
plt . title ( " Hermite Blending Functions and Resulting Curve " )
plt . xlabel ( " $u$ " )
plt . ylabel ( " $h ( u ) $ and $C ( u ) $ " )
plt . axhline (0 , color = " black " , linewidth =0.8 , linestyle = " --" )
plt . legend ()
plt . grid ( True )
# Show the plot
Page 6 PNS2024003
Assignment 4 Research Methodology 2
plt . show ()
Page 7 PNS2024003
Assignment 4 Research Methodology 2
Derive the Bezier Spline
Solution
We will now substitute the Bezier derivative relationships into the Hermite curve
matrix form to derive the desired result.
Step 1: Hermite Curve Representation
The cubic Hermite curve is expressed as:
P (t) = uT · MH · GH
Where:
uT = [t3 , t2 , t, 1],
2 −2 1 1
−3 3 −2 −1
MH =
0
,
0 1 0
1 0 0 0
P0
P3
GH = P0′ .
P1′
Step 2: Tangent Substitution Using Bezier Derivatives
For a cubic Bezier curve, the tangents at the endpoints are given by the relationships:
Pi′ = 3(Pi+1 − Pi ), for i = 0, 1.
This gives:
P0′ = 3(P1 − P0 ),
P1′ = 3(P3 − P2 ).
Substituting these into the Hermite geometry matrix, we get:
P0
P3
GH = 3(P1 − P0 ) .
3(P3 − P2 )
Page 8 PNS2024003
Assignment 4 Research Methodology 2
Step 3: Substitution into Hermite Matrix Form
Substitute GH into the Hermite curve equation:
P0
P3
P (t) = uT · MH ·
3(P1 − P0 ) .
3(P3 − P2 )
First, compute MH · GH :
2 −2 1 1 P0
−3 3 −2 −1 P3
MH · GH = · .
0 0 1 0 3(P1 − P0 )
1 0 0 0 3(P3 − P2 )
Step 4: Compute Each Row of MH · GH
First row:
2P0 − 2P3 + 3(P1 − P0 ) + 3(P3 − P2 ) = −P0 + 3P1 − 3P2 + P3 .
Second row:
−3P0 + 3P3 − 6(P1 − P0 ) − 3(P3 − P2 ) = 3P0 − 6P1 + 3P2 .
Third row:
3(P1 − P0 ).
Fourth row:
P0 .
Thus:
−P0 + 3P1 − 3P2 + P3
3P0 − 6P1 + 3P2
MH · GH = .
3(P1 − P0 )
P0
Step 5: Expressing in Bezier Form
The general cubic Bezier curve is expressed as:
P (t) = uT · MB · GB
Where:
−1 3 −3 1 P0
3 −6 3 0 P1
MB =
−3 3
, GB =
P2 .
0 0
1 0 0 0 P3
Page 9 PNS2024003
Assignment 4 Research Methodology 2
From the above computation, we observe that MH · GH matches the rows of MB · GB
when the geometry terms are assigned to Bezier control points P1 and P2 .
Final Result
The cubic Bezier curve is expressed as:
−1 3 −3 1 P0
3 −6 3 0 · P1 .
P (t) = [t3 t2 t 1] ·
−3 3 0 0 P2
1 0 0 0 P3
Bezier Blending Functions
Finally, we determine the 4 Bezier blending functions, which are the elements of the
vector uT = [t3 , t2 , t, 1] multiplied by the Bezier matrix MB :
The Bezier blending functions are:
B0 (t) = −t3 + 3t2 − 3t + 1,
B1 (t) = 3t3 − 6t2 + 3t,
B2 (t) = −3t3 + 3t2 ,
B3 (t) = t3 .
These functions provide the weights for the control points P0 , P1 , P2 , P3 at any given
value of t.
Page 10 PNS2024003
Assignment 4 Research Methodology 2
Bezier Blending Functions and Plot
To compute and visualize the Bezier blending functions, the following Python code was
used:
import numpy as np
import matplotlib . pyplot as plt
# Define the Bezier blending functions
def B0 ( t ) :
return -t **3 + 3* t **2 - 3* t + 1
def B1 ( t ) :
return 3* t **3 - 6* t **2 + 3* t
def B2 ( t ) :
return -3* t **3 + 3* t **2
def B3 ( t ) :
return t **3
# Generate t values from 0 to 1
t = np . linspace (0 , 1 , 500)
# Compute the values of the Bezier blending functions
B0_vals = B0 ( t )
B1_vals = B1 ( t )
B2_vals = B2 ( t )
B3_vals = B3 ( t )
# Plot the Bezier blending functions
plt . figure ( figsize =(8 , 6) )
plt . plot (t , B0_vals , label = r ’ $B_0 ( t ) = -t ^3 + 3 t ^2 - 3 t + 1 $ ’ ,
color = ’ blue ’)
plt . plot (t , B1_vals , label = r ’ $B_1 ( t ) = 3 t ^3 - 6 t ^2 + 3 t$ ’ , color =
’ green ’)
plt . plot (t , B2_vals , label = r ’ $B_2 ( t ) = -3 t ^3 + 3 t ^2 $ ’ , color = ’ red
’)
plt . plot (t , B3_vals , label = r ’ $B_3 ( t ) = t ^3 $ ’ , color = ’ purple ’)
# Add labels and title
plt . xlabel ( ’t ’ , fontsize =12)
plt . ylabel ( ’ Blending Functions ’ , fontsize =12)
plt . title ( ’ Bezier Blending Functions ’ , fontsize =14)
plt . legend ( loc = ’ best ’)
# Show the plot
plt . grid ( True )
plt . show ()
The plot below shows the four Bezier blending functions:
Page 11 PNS2024003
Assignment 4 Research Methodology 2
Page 12 PNS2024003
Assignment 4 Research Methodology 2
Bezier Blending Functions and New Curve
To compute the new curve obtained by multiplying the Bezier blending functions by 2.05
and adding them together, the following Python code was used:
import numpy as np
import matplotlib . pyplot as plt
# Define the Bezier blending functions
def B0 ( t ) :
return -t **3 + 3* t **2 - 3* t + 1
def B1 ( t ) :
return 3* t **3 - 6* t **2 + 3* t
def B2 ( t ) :
return -3* t **3 + 3* t **2
def B3 ( t ) :
return t **3
# Generate t values from 0 to 1
t = np . linspace (0 , 1 , 500)
# Compute the values of the Bezier blending functions
B0_vals = B0 ( t )
B1_vals = B1 ( t )
B2_vals = B2 ( t )
B3_vals = B3 ( t )
# Multiply all Bezier blending functions by 2.05 and sum them
C_vals = 2.05 * ( B0_vals + B1_vals + B2_vals + B3_vals )
# Plot the original Bezier blending functions and the new curve
plt . figure ( figsize =(8 , 6) )
plt . plot (t , B0_vals , label = r ’ $B_0 ( t ) $ ’ , color = ’ blue ’)
plt . plot (t , B1_vals , label = r ’ $B_1 ( t ) $ ’ , color = ’ green ’)
plt . plot (t , B2_vals , label = r ’ $B_2 ( t ) $ ’ , color = ’ red ’)
plt . plot (t , B3_vals , label = r ’ $B_3 ( t ) $ ’ , color = ’ purple ’)
plt . plot (t , C_vals , label = r ’ $C ( t ) = 2.05 \ cdot ( B_0 ( t ) + B_1 ( t ) +
B_2 ( t ) + B_3 ( t ) ) $ ’ , color = ’ orange ’ , linestyle = ’ -- ’)
# Add labels and title
plt . xlabel ( ’t ’ , fontsize =12)
plt . ylabel ( ’ Blending Functions ’ , fontsize =12)
plt . title ( ’ Bezier Blending Functions and New Curve ’ , fontsize =14)
plt . legend ( loc = ’ best ’)
# Show the plot
plt . grid ( True )
plt . show ()
Page 13 PNS2024003
Assignment 4 Research Methodology 2
The plot below shows the four Bezier blending functions along with the new curve
obtained by multiplying and adding them:
Collab Codes Link
All codes are available in this Colab link.
https://colab.research.google.com/drive/1Uvz1-Y-HTj-IQFgxT0HneIBlHUKD3E7f?usp=sharing
Page 14 PNS2024003