SlideShare a Scribd company logo
1 of 32
Mobile Game Programming:
Hermite Spline
jintaeks@dongseo.ac.kr
Division of Digital Contents, DongSeo University.
October 2016
Type of functions
Explicit function
y=
2
𝑅2 − 𝑥2 or y=-
2
𝑅2 − 𝑥2
Implicit function
x2+y2=R2
Parametric representation
x=Rcosθ, y=Rsinθ (0≤ θ < 2π)
2
Order of continuity
 The various order of parametric continuity can be described
as follows:[5]
 C−1: curves include discontinuities
 C0: curves are joined
 C1: first derivatives are continuous
 C2: first and second derivatives are continuous
 Cn: first through nth derivatives are continuous
3
Spline
 In mathematics, a spline is a
numeric function that is piecewise-defined
by polynomial functions.
– A flexible device which can be bent to the
desired shape is known as a flat spline.
 In interpolation problems, spline
interpolation is often preferred
to polynomial interpolation because it
yields similar results to interpolating with
higher degree polynomials while avoiding
instability.
 The most commonly used splines
are cubic splines.
4
Ex) Quadratic spline
5
Ex) Cubic spline
6
Definition of spline
 A spline is a piecewise-polynomial real function
S:[a,b]  R
 on an interval [a,b] composed of k subintervals [ti-1,ti] with
a=t0<t1< … <tk-1<tk=b.
 The restriction of S to an interval i is a polynomial
Pi:[ti-1,ti]R,
 so that
S(t)=P1(t), t0<= t <= t1,
S(t)=P2(t), t1<= t <= t2,
…
S(t)=Pk(t), tk-1<= t <= tk,
 The highest order of the polynomials Pi(t) is said to be
the order of the spline S.
7
Cubic spline
 In numerical analysis, a cubic spline is a spline where each
piece is a third-degree polynomial.
 A cubic Hermite spline Specified by its values and
first derivatives at the end points of the
corresponding domain interval.
8
Unit interval (0,1)
 On the interval (0,1), given a starting point p0 at t = 0 and an
ending point p1 at t = 1 with starting tangent m0 at t = 0 and
ending tangent m1 at t = 1, the polynomial can be defined by
 where t ∈ [0,1].
9
 a point Q(t) on a curve at parameter t can be defined a cubic
equations for each value:
Q(t)=
𝑥(𝑡)
𝑦(𝑡)
=
𝑎 𝑥 𝑡3 + 𝑏𝑥𝑡2 + 𝑐𝑥𝑡 + 𝑑𝑦
𝑎 𝑦 𝑡3 + 𝑏𝑦𝑡2 + 𝑐𝑦𝑡 + 𝑑𝑦
 We can define coefficient matrix C and parameter matrix T,
then Q(t) can be defined like this:
T=
𝑡3
𝑡2
𝑡
1
C=
𝑎 𝑥 𝑏 𝑥 𝑐 𝑥 𝑑 𝑥
𝑎 𝑦 𝑏 𝑦 𝑐 𝑦 𝑑 𝑦
Q(t)=
𝑥(𝑡)
𝑦(𝑡)
=𝐶‧𝑇
10
 We will decompose C with 2×4 Geometry Matrix G and 4×4
Basis Matrix M.
C=G‧M
Q(t)=
𝑥(𝑡)
𝑦(𝑡)
=𝑪‧𝑇 = 𝐺‧M‧T
=
𝑔1𝑥 𝑔2𝑥
𝑔3𝑥 𝑔4𝑥
𝑔1𝑦 𝑔2𝑦
𝑔3𝑦 𝑔4𝑦
𝑚11 𝑚12 𝑚13 𝑚14
𝑚21 𝑚22 𝑚23 𝑚24
𝑚31 𝑚32 𝑚33 𝑚34
𝑚41 𝑚42 𝑚43 𝑚44
𝑡3
𝑡2
𝑡
1
11
Geometry matrix G
 has an information about control data.
 in case of Hermite spline, it has two points and tangent
vectors for each point.
– P1, P2, R1, R2
Base matrix M
 a coefficient matrix for the blending functions.
 blending function means M‧T.
 the summation of all blending functions is 1.
– it means that spline curve calculates the weighted average for control
points.
12
Hermite Spline
 Specified by its values and first derivatives at the end points
of the corresponding domain interval
Geometry matrix G
G=
𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥
𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦
13
Find Base matrix M
 Four conditions to find Base matrix M.
 Begin point is (P1x, P1y), and End point is (P4x, P4y).
Q(0)=
𝑃1𝑥
𝑃1𝑦
Q(1)=
𝑃4𝑥
𝑃4𝑦
 Derivative at Begin point is (R1x, R1y), and derivative at End
point is (R4x, R4y).
Q'(0)=
𝑅1𝑥
𝑅1𝑦
Q'(1)=
𝑅4𝑥
𝑅4𝑦
14
for two end points
 Q(0)=
𝑃1𝑥
𝑃1𝑦
= 𝐺‧M‧T
=
𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥
𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦
𝑚11 𝑚12 𝑚13 𝑚14
𝑚21 𝑚22 𝑚23 𝑚24
𝑚31 𝑚32 𝑚33 𝑚34
𝑚41 𝑚42 𝑚43 𝑚44
𝑡3
𝑡2
𝑡
1
=𝐺‧M
0
0
0
1
 Q(1)=
𝑃4𝑥
𝑃4𝑦
= 𝐺‧M
1
1
1
1
15
for two tangent vector
 Q'(0)=
𝑅1𝑥
𝑅1𝑦
= 𝐺‧M‧T′
=
𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥
𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦
𝑚11 𝑚12 𝑚13 𝑚14
𝑚21 𝑚22 𝑚23 𝑚24
𝑚31 𝑚32 𝑚33 𝑚34
𝑚41 𝑚42 𝑚43 𝑚44
3𝑡2
2𝑡
1
0
=𝐺‧M
0
0
1
0
 Q'(1)=
𝑅4𝑥
𝑅4𝑦
= 𝐺‧M
3
2
1
0
16
Base matrix M

𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥
𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦
= 𝐺 = 𝐺‧𝑀
0 1 0 3
0 1 0 2
0 1 1 1
1 1 0 0
= 𝐺‧𝑀‧𝑀-1
0 1 0 3
0 1 0 2
0 1 1 1
1 1 0 0
=M-1
 M=
2 −3 0 1
−2 3 0 0
1 −2 1 0
1 −1 0 0
17
Blending function
 Q(t)=
𝑥(𝑡)
𝑦(𝑡)
= 𝐺‧M‧T = 𝐺‧𝐵
=(2t3−3t2+1)
𝑃1𝑥
𝑃1𝑦
+(-2t3+3t2)
𝑃4𝑥
𝑃4𝑦
+(t3-2t2+1)
𝑅1𝑥
𝑅1𝑦
+(t3-t2)
𝑅4𝑥
𝑅4𝑦
.
18
2 −3 0 1
−2 3 0 0
1 −2 1 0
1 −1 0 0
𝑡3
𝑡2
𝑡1
0
Meaning of tangent vector R
19
P1 P4
R4
R1
Implement Hermite Spline
class KHermiteCurve
{
public:
float m_a;
float m_b;
float m_c;
float m_d;
20
class KHermiteCurve
{
public:
/// constructor.
/// @param p1: begin point
/// @param p2: end point
/// @param v1: tangent vector at begin point
/// @param v2: tangent vector at end point
KHermiteCurve(float p1, float p2, float v1, float v2)
{
m_d = p1;
m_c = v1;
m_b = -3.0f*p1 + 3.0f*p2 - 2.0f*v1 - v2;
m_a = 2.0f*p1 - 2.0f*p2 + v1 + v2;
}//KHermiteCurve()
21
/// set coefficient of Hermite curve
inline void Construct(float p1, float p2, float v1, float v2)
{
m_d = p1;
m_c = v1;
m_b = -3.0f*p1 + 3.0f*p2 - 2.0f*v1 - v2;
m_a = 2.0f*p1 - 2.0f*p2 + v1 + v2;
}//Construct()
/// calculate first derivative on parameter u.
/// can be used to get tangent vector at u.
/// derivative of equation t^3 + t^2 + t + 1
inline float CalculateDxDu(float u) const
{
return 3.0f*m_a*u*u + 2.0f*m_b*u + m_c;
}//CalculateDxDu()
22
/// get value at parameter u.
inline float CalculateX(float u) const
{
float uu, uuu;
uu = u * u;
uuu = uu * u;
return m_a*uuu + m_b*uu + m_c*u + m_d;
}//CalculateX()
23
KHermiteSpline2
class KHermiteSpline2
{
private:
KHermiteCurve m_aHermiteCurve[2];
public:
/// constructor.
KHermiteSpline2(){}
KHermiteSpline2( const KVector& p0, const KVector& p1, const KVector& dp0, const
KVector& dp1 )
{
m_aHermiteCurve[ 0 ].Construct( p0.m_x, p1.m_x, dp0.m_x, dp1.m_x );
m_aHermiteCurve[ 1 ].Construct( p0.m_y, p1.m_y, dp0.m_y, dp1.m_y );
}//KHermiteSpline2()
24
inline void Construct( const KVector& p0, const KVector& p1, const KVector& dp0,
const KVector& dp1 )
{
m_aHermiteCurve[ 0 ].Construct( p0.m_x, p1.m_x, dp0.m_x, dp1.m_x );
m_aHermiteCurve[ 1 ].Construct( p0.m_y, p1.m_y, dp0.m_y, dp1.m_y );
}//Construct()
25
inline const KVector GetPosition( float u_ ) const
{
return KVector( m_aHermiteCurve[ 0 ].CalculateX( u_ ), m_aHermiteCurve[ 1
].CalculateX( u_ ), 0.f );
}//GetPosition()
inline const KVector GetTangent( float u_ ) const
{
return KVector( m_aHermiteCurve[ 0 ].CalculateDxDu( u_ ), m_aHermiteCurve[ 1
].CalculateDxDu( u_ ), 0.f );
}//GetTangent()
26
Draw a tangent line at u
const float u = 0.5f;
KVector position = spline.GetPosition(u);
KVector tangent = spline.GetTangent(u);
DrawLine(hdc, position, position + tangent * 100.f);
27
Combine Splines
28
Line in 3D space
 Given two 3D points P1 and P2, we can define the line that
passes through these points parametrically as
P(t ) = (1− t )P1 + tP2
 A ray is a line having a single endpoint S and extending to
infinity in a given direction V. Rays are typically expressed by
the parametric equation
P(t ) = S + tV
 Note that this equation is equivalent to previous equation if
we let S = P1 and V = P2 − P1.
29
Distance between a point and a line
30
Spline path tracing demo
31
Hermite spline english_20161201_jintaeks

More Related Content

What's hot

Part 4-Types and mathematical representations of Curves .pptx
Part 4-Types and mathematical representations of Curves .pptxPart 4-Types and mathematical representations of Curves .pptx
Part 4-Types and mathematical representations of Curves .pptx
Khalil Alhatab
 
B spline surfeces
B spline surfecesB spline surfeces
B spline surfeces
ramac123
 
Coons bicubic surface
Coons bicubic surfaceCoons bicubic surface
Coons bicubic surface
ramac123
 

What's hot (20)

Bezier Curve and Spline Curve
Bezier Curve and Spline CurveBezier Curve and Spline Curve
Bezier Curve and Spline Curve
 
Part 4-Types and mathematical representations of Curves .pptx
Part 4-Types and mathematical representations of Curves .pptxPart 4-Types and mathematical representations of Curves .pptx
Part 4-Types and mathematical representations of Curves .pptx
 
B-spline
B-spline B-spline
B-spline
 
Geometric modeling
Geometric modelingGeometric modeling
Geometric modeling
 
B spline surfeces
B spline surfecesB spline surfeces
B spline surfeces
 
Design of rope, belt and chain by Aliyi Umer
Design of rope, belt and chain by Aliyi UmerDesign of rope, belt and chain by Aliyi Umer
Design of rope, belt and chain by Aliyi Umer
 
Geometric model & curve
Geometric model & curveGeometric model & curve
Geometric model & curve
 
Surface models
Surface modelsSurface models
Surface models
 
oblique planes
oblique planesoblique planes
oblique planes
 
Solid modelling
Solid modellingSolid modelling
Solid modelling
 
Geometric Curves
Geometric Curves Geometric Curves
Geometric Curves
 
CAD - UNIT 2 (Geometric Modelling)
CAD - UNIT 2 (Geometric Modelling)CAD - UNIT 2 (Geometric Modelling)
CAD - UNIT 2 (Geometric Modelling)
 
Bezier and Spline Curves and Surfaces
Bezier and Spline Curves and SurfacesBezier and Spline Curves and Surfaces
Bezier and Spline Curves and Surfaces
 
Surfaces
SurfacesSurfaces
Surfaces
 
Surface representation
Surface representationSurface representation
Surface representation
 
Geometric Modeling
Geometric Modeling Geometric Modeling
Geometric Modeling
 
CAD / CAM NURBS
CAD / CAM NURBSCAD / CAM NURBS
CAD / CAM NURBS
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
Techniques for Geometric Modelling
Techniques for Geometric ModellingTechniques for Geometric Modelling
Techniques for Geometric Modelling
 
Coons bicubic surface
Coons bicubic surfaceCoons bicubic surface
Coons bicubic surface
 

Viewers also liked (10)

Analytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_IntroductionAnalytical chemistry_Instrumentation_Introduction
Analytical chemistry_Instrumentation_Introduction
 
[Download] rev chapter-5-june26th
[Download] rev chapter-5-june26th[Download] rev chapter-5-june26th
[Download] rev chapter-5-june26th
 
Presentation non parametric
Presentation non parametricPresentation non parametric
Presentation non parametric
 
Parametric equations
Parametric equationsParametric equations
Parametric equations
 
hermite cubic spline curve
hermite cubic spline curvehermite cubic spline curve
hermite cubic spline curve
 
Perspective projection
Perspective projectionPerspective projection
Perspective projection
 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
 
Presentation on bezier curve
Presentation on bezier curvePresentation on bezier curve
Presentation on bezier curve
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Non parametric tests
Non parametric testsNon parametric tests
Non parametric tests
 

Similar to Hermite spline english_20161201_jintaeks

New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...
Alexander Litvinenko
 

Similar to Hermite spline english_20161201_jintaeks (20)

E33018021
E33018021E33018021
E33018021
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics
 
Litvinenko low-rank kriging +FFT poster
Litvinenko low-rank kriging +FFT  posterLitvinenko low-rank kriging +FFT  poster
Litvinenko low-rank kriging +FFT poster
 
Designing Parametric cubic Curves
Designing Parametric cubic CurvesDesigning Parametric cubic Curves
Designing Parametric cubic Curves
 
Hull White model presentation
Hull White model presentationHull White model presentation
Hull White model presentation
 
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
Computing f-Divergences and Distances of\\ High-Dimensional Probability Densi...
 
Informe laboratorio n°1
Informe laboratorio n°1Informe laboratorio n°1
Informe laboratorio n°1
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...Low rank tensor approximation of probability density and characteristic funct...
Low rank tensor approximation of probability density and characteristic funct...
 
kactl.pdf
kactl.pdfkactl.pdf
kactl.pdf
 
assignment_2
assignment_2assignment_2
assignment_2
 
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
2018 MUMS Fall Course - Statistical and Mathematical Techniques for Sensitivi...
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...
 
residue
residueresidue
residue
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
 
Tp problèmes-à-valeurs-initiales
Tp problèmes-à-valeurs-initialesTp problèmes-à-valeurs-initiales
Tp problèmes-à-valeurs-initiales
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
 
Csm chapters12
Csm chapters12Csm chapters12
Csm chapters12
 
K-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source codeK-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source code
 

More from JinTaek Seo

Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksBeginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
JinTaek Seo
 

More from JinTaek Seo (20)

Neural network 20161210_jintaekseo
Neural network 20161210_jintaekseoNeural network 20161210_jintaekseo
Neural network 20161210_jintaekseo
 
05 heap 20161110_jintaeks
05 heap 20161110_jintaeks05 heap 20161110_jintaeks
05 heap 20161110_jintaeks
 
02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo02 linked list_20160217_jintaekseo
02 linked list_20160217_jintaekseo
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
03 fsm how_toimplementai_state_20161006_jintaeks
03 fsm how_toimplementai_state_20161006_jintaeks03 fsm how_toimplementai_state_20161006_jintaeks
03 fsm how_toimplementai_state_20161006_jintaeks
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksBeginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
 
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeksBeginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
Beginning direct3d gameprogramming07_lightsandmaterials_20161117_jintaeks
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks
Beginning direct3d gameprogramming05_thebasics_20160421_jintaeksBeginning direct3d gameprogramming05_thebasics_20160421_jintaeks
Beginning direct3d gameprogramming05_thebasics_20160421_jintaeks
 
Beginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeks
Beginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeksBeginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeks
Beginning direct3d gameprogramming04_3dfundamentals_20160414_jintaeks
 
Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks
Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeksBeginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks
Beginning direct3d gameprogramming02_overviewofhalandcom_20160408_jintaeks
 
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
Beginning direct3d gameprogramming01_thehistoryofdirect3dgraphics_20160407_ji...
 
Beginning direct3d gameprogramming01_20161102_jintaeks
Beginning direct3d gameprogramming01_20161102_jintaeksBeginning direct3d gameprogramming01_20161102_jintaeks
Beginning direct3d gameprogramming01_20161102_jintaeks
 
Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks
Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeksBeginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks
Beginning direct3d gameprogramming03_programmingconventions_20160414_jintaeks
 
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeksBeginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
Beginning direct3d gameprogrammingmath06_transformations_20161019_jintaeks
 
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeksBeginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
Beginning direct3d gameprogrammingmath05_matrices_20160515_jintaeks
 
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeksBeginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
Beginning direct3d gameprogrammingmath04_calculus_20160324_jintaeks
 
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeksBeginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
Beginning direct3d gameprogrammingmath03_vectors_20160328_jintaeks
 

Recently uploaded

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 

Hermite spline english_20161201_jintaeks

  • 1. Mobile Game Programming: Hermite Spline jintaeks@dongseo.ac.kr Division of Digital Contents, DongSeo University. October 2016
  • 2. Type of functions Explicit function y= 2 𝑅2 − 𝑥2 or y=- 2 𝑅2 − 𝑥2 Implicit function x2+y2=R2 Parametric representation x=Rcosθ, y=Rsinθ (0≤ θ < 2π) 2
  • 3. Order of continuity  The various order of parametric continuity can be described as follows:[5]  C−1: curves include discontinuities  C0: curves are joined  C1: first derivatives are continuous  C2: first and second derivatives are continuous  Cn: first through nth derivatives are continuous 3
  • 4. Spline  In mathematics, a spline is a numeric function that is piecewise-defined by polynomial functions. – A flexible device which can be bent to the desired shape is known as a flat spline.  In interpolation problems, spline interpolation is often preferred to polynomial interpolation because it yields similar results to interpolating with higher degree polynomials while avoiding instability.  The most commonly used splines are cubic splines. 4
  • 7. Definition of spline  A spline is a piecewise-polynomial real function S:[a,b]  R  on an interval [a,b] composed of k subintervals [ti-1,ti] with a=t0<t1< … <tk-1<tk=b.  The restriction of S to an interval i is a polynomial Pi:[ti-1,ti]R,  so that S(t)=P1(t), t0<= t <= t1, S(t)=P2(t), t1<= t <= t2, … S(t)=Pk(t), tk-1<= t <= tk,  The highest order of the polynomials Pi(t) is said to be the order of the spline S. 7
  • 8. Cubic spline  In numerical analysis, a cubic spline is a spline where each piece is a third-degree polynomial.  A cubic Hermite spline Specified by its values and first derivatives at the end points of the corresponding domain interval. 8
  • 9. Unit interval (0,1)  On the interval (0,1), given a starting point p0 at t = 0 and an ending point p1 at t = 1 with starting tangent m0 at t = 0 and ending tangent m1 at t = 1, the polynomial can be defined by  where t ∈ [0,1]. 9
  • 10.  a point Q(t) on a curve at parameter t can be defined a cubic equations for each value: Q(t)= 𝑥(𝑡) 𝑦(𝑡) = 𝑎 𝑥 𝑡3 + 𝑏𝑥𝑡2 + 𝑐𝑥𝑡 + 𝑑𝑦 𝑎 𝑦 𝑡3 + 𝑏𝑦𝑡2 + 𝑐𝑦𝑡 + 𝑑𝑦  We can define coefficient matrix C and parameter matrix T, then Q(t) can be defined like this: T= 𝑡3 𝑡2 𝑡 1 C= 𝑎 𝑥 𝑏 𝑥 𝑐 𝑥 𝑑 𝑥 𝑎 𝑦 𝑏 𝑦 𝑐 𝑦 𝑑 𝑦 Q(t)= 𝑥(𝑡) 𝑦(𝑡) =𝐶‧𝑇 10
  • 11.  We will decompose C with 2×4 Geometry Matrix G and 4×4 Basis Matrix M. C=G‧M Q(t)= 𝑥(𝑡) 𝑦(𝑡) =𝑪‧𝑇 = 𝐺‧M‧T = 𝑔1𝑥 𝑔2𝑥 𝑔3𝑥 𝑔4𝑥 𝑔1𝑦 𝑔2𝑦 𝑔3𝑦 𝑔4𝑦 𝑚11 𝑚12 𝑚13 𝑚14 𝑚21 𝑚22 𝑚23 𝑚24 𝑚31 𝑚32 𝑚33 𝑚34 𝑚41 𝑚42 𝑚43 𝑚44 𝑡3 𝑡2 𝑡 1 11
  • 12. Geometry matrix G  has an information about control data.  in case of Hermite spline, it has two points and tangent vectors for each point. – P1, P2, R1, R2 Base matrix M  a coefficient matrix for the blending functions.  blending function means M‧T.  the summation of all blending functions is 1. – it means that spline curve calculates the weighted average for control points. 12
  • 13. Hermite Spline  Specified by its values and first derivatives at the end points of the corresponding domain interval Geometry matrix G G= 𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥 𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦 13
  • 14. Find Base matrix M  Four conditions to find Base matrix M.  Begin point is (P1x, P1y), and End point is (P4x, P4y). Q(0)= 𝑃1𝑥 𝑃1𝑦 Q(1)= 𝑃4𝑥 𝑃4𝑦  Derivative at Begin point is (R1x, R1y), and derivative at End point is (R4x, R4y). Q'(0)= 𝑅1𝑥 𝑅1𝑦 Q'(1)= 𝑅4𝑥 𝑅4𝑦 14
  • 15. for two end points  Q(0)= 𝑃1𝑥 𝑃1𝑦 = 𝐺‧M‧T = 𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥 𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦 𝑚11 𝑚12 𝑚13 𝑚14 𝑚21 𝑚22 𝑚23 𝑚24 𝑚31 𝑚32 𝑚33 𝑚34 𝑚41 𝑚42 𝑚43 𝑚44 𝑡3 𝑡2 𝑡 1 =𝐺‧M 0 0 0 1  Q(1)= 𝑃4𝑥 𝑃4𝑦 = 𝐺‧M 1 1 1 1 15
  • 16. for two tangent vector  Q'(0)= 𝑅1𝑥 𝑅1𝑦 = 𝐺‧M‧T′ = 𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥 𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦 𝑚11 𝑚12 𝑚13 𝑚14 𝑚21 𝑚22 𝑚23 𝑚24 𝑚31 𝑚32 𝑚33 𝑚34 𝑚41 𝑚42 𝑚43 𝑚44 3𝑡2 2𝑡 1 0 =𝐺‧M 0 0 1 0  Q'(1)= 𝑅4𝑥 𝑅4𝑦 = 𝐺‧M 3 2 1 0 16
  • 17. Base matrix M  𝑃1𝑥 𝑃4𝑥 𝑅1𝑥 𝑅4𝑥 𝑃1𝑦 𝑃4𝑦 𝑅1𝑦 𝑅4𝑦 = 𝐺 = 𝐺‧𝑀 0 1 0 3 0 1 0 2 0 1 1 1 1 1 0 0 = 𝐺‧𝑀‧𝑀-1 0 1 0 3 0 1 0 2 0 1 1 1 1 1 0 0 =M-1  M= 2 −3 0 1 −2 3 0 0 1 −2 1 0 1 −1 0 0 17
  • 18. Blending function  Q(t)= 𝑥(𝑡) 𝑦(𝑡) = 𝐺‧M‧T = 𝐺‧𝐵 =(2t3−3t2+1) 𝑃1𝑥 𝑃1𝑦 +(-2t3+3t2) 𝑃4𝑥 𝑃4𝑦 +(t3-2t2+1) 𝑅1𝑥 𝑅1𝑦 +(t3-t2) 𝑅4𝑥 𝑅4𝑦 . 18 2 −3 0 1 −2 3 0 0 1 −2 1 0 1 −1 0 0 𝑡3 𝑡2 𝑡1 0
  • 19. Meaning of tangent vector R 19 P1 P4 R4 R1
  • 20. Implement Hermite Spline class KHermiteCurve { public: float m_a; float m_b; float m_c; float m_d; 20
  • 21. class KHermiteCurve { public: /// constructor. /// @param p1: begin point /// @param p2: end point /// @param v1: tangent vector at begin point /// @param v2: tangent vector at end point KHermiteCurve(float p1, float p2, float v1, float v2) { m_d = p1; m_c = v1; m_b = -3.0f*p1 + 3.0f*p2 - 2.0f*v1 - v2; m_a = 2.0f*p1 - 2.0f*p2 + v1 + v2; }//KHermiteCurve() 21
  • 22. /// set coefficient of Hermite curve inline void Construct(float p1, float p2, float v1, float v2) { m_d = p1; m_c = v1; m_b = -3.0f*p1 + 3.0f*p2 - 2.0f*v1 - v2; m_a = 2.0f*p1 - 2.0f*p2 + v1 + v2; }//Construct() /// calculate first derivative on parameter u. /// can be used to get tangent vector at u. /// derivative of equation t^3 + t^2 + t + 1 inline float CalculateDxDu(float u) const { return 3.0f*m_a*u*u + 2.0f*m_b*u + m_c; }//CalculateDxDu() 22
  • 23. /// get value at parameter u. inline float CalculateX(float u) const { float uu, uuu; uu = u * u; uuu = uu * u; return m_a*uuu + m_b*uu + m_c*u + m_d; }//CalculateX() 23
  • 24. KHermiteSpline2 class KHermiteSpline2 { private: KHermiteCurve m_aHermiteCurve[2]; public: /// constructor. KHermiteSpline2(){} KHermiteSpline2( const KVector& p0, const KVector& p1, const KVector& dp0, const KVector& dp1 ) { m_aHermiteCurve[ 0 ].Construct( p0.m_x, p1.m_x, dp0.m_x, dp1.m_x ); m_aHermiteCurve[ 1 ].Construct( p0.m_y, p1.m_y, dp0.m_y, dp1.m_y ); }//KHermiteSpline2() 24
  • 25. inline void Construct( const KVector& p0, const KVector& p1, const KVector& dp0, const KVector& dp1 ) { m_aHermiteCurve[ 0 ].Construct( p0.m_x, p1.m_x, dp0.m_x, dp1.m_x ); m_aHermiteCurve[ 1 ].Construct( p0.m_y, p1.m_y, dp0.m_y, dp1.m_y ); }//Construct() 25
  • 26. inline const KVector GetPosition( float u_ ) const { return KVector( m_aHermiteCurve[ 0 ].CalculateX( u_ ), m_aHermiteCurve[ 1 ].CalculateX( u_ ), 0.f ); }//GetPosition() inline const KVector GetTangent( float u_ ) const { return KVector( m_aHermiteCurve[ 0 ].CalculateDxDu( u_ ), m_aHermiteCurve[ 1 ].CalculateDxDu( u_ ), 0.f ); }//GetTangent() 26
  • 27. Draw a tangent line at u const float u = 0.5f; KVector position = spline.GetPosition(u); KVector tangent = spline.GetTangent(u); DrawLine(hdc, position, position + tangent * 100.f); 27
  • 29. Line in 3D space  Given two 3D points P1 and P2, we can define the line that passes through these points parametrically as P(t ) = (1− t )P1 + tP2  A ray is a line having a single endpoint S and extending to infinity in a given direction V. Rays are typically expressed by the parametric equation P(t ) = S + tV  Note that this equation is equivalent to previous equation if we let S = P1 and V = P2 − P1. 29
  • 30. Distance between a point and a line 30