How Movies Break Physics Andrea Velasco Niloofar Rajaeifar Toby Harris Peter Bellaby.
1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.
-
Upload
dana-harrell -
Category
Documents
-
view
221 -
download
1
Transcript of 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.
![Page 1: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/1.jpg)
1
CO2301 - Games Development 1Week 12
Interpolation, Path Smoothing & Splines
CO2301 - Games Development 1Week 12
Interpolation, Path Smoothing & Splines
Gareth BellabyGareth Bellaby
![Page 2: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/2.jpg)
2
TopicsTopics
1. Introduction - Path Smoothing
2. Parametric line equations
3. Interpolation
4. Path Smoothing & Splines
![Page 3: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/3.jpg)
3
Topic 1Topic 1
Introduction - Path Smoothing
![Page 4: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/4.jpg)
4
Path SmoothingPath Smoothing
• The path generated by the pathfinding algorithms are composed of unnatural looking straight lines and abrupt turns. This is true whichever representation is used.
• Path Smoothing is about smoothing the path and making something more aesthetically pleasing.
![Page 5: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/5.jpg)
5
Path SmoothingPath Smoothing
• We have a set of points.
• We want to instead to have a curved path or line.
• One way to do this is so employ a spline. A spline takes two or more points and draws a curve based on the location of the points.
• The word spline is an architectural term- it was a flexible wooden rod used to draw out a curve, e.g. for a pillar section.
• There are different types of spline. The curve they generate have different characteristics.
![Page 6: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/6.jpg)
6
Topic 2Topic 2
Parametric line equations
![Page 7: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/7.jpg)
7
Parametric equationParametric equation
• A parametric equation is simply one that contains a parameter.
• In this context, the parameter means a variable.
• Two points are needed to calculate the equation for a line.
![Page 8: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/8.jpg)
8
Parametric equationParametric equation
• One convention is to use t for the parameter.
• All of the points lying along a line can be expressed using the following formula:
)()( 010 PPtPtL
• In practice you will express each of the x, y and z components separately, e.g.
)()(
)()(
)()(
010
010
010
zztztz
yytyty
xxtxtx
![Page 9: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/9.jpg)
9
Parametric equationParametric equation
• P0 is the point where the line starts.
• P1 - P0 is simply the vector (or slope) between two points.
• t is a variable which ranges across all of the possible points along the line.
)()( 010 PPtPtL
![Page 10: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/10.jpg)
10
ExampleExample
)3(1)(
)14(1)(
)()( 010
ttx
ttx
xxtxtx
)2(2)(
)24(2)(
)()( 010
tty
tty
yytyty
![Page 11: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/11.jpg)
11
IntervalsIntervals
• Note that the parametric line equation can be used to derive regular intervals along the line.
• The half-way point is calculated if t = 0.5.
• The quarter-way point is calculated if t = 0.25.
![Page 12: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/12.jpg)
12
Example: mid-pointExample: mid-point
5.2)5.0(
3*5.01)5.0(
)3(1)(
x
x
ttx
3)5.0(
2*5.02)5.0(
)2(2)(
y
y
tty
![Page 13: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/13.jpg)
13
Example: quarter-pointExample: quarter-point
75.1)25.0(
3*25.01)25.0(
)3(1)(
x
x
ttx
5.2)25.0(
2*25.02)25.0(
)2(2)(
y
y
tty
![Page 14: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/14.jpg)
14
Topic 3Topic 3
Interpolation
![Page 15: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/15.jpg)
15
InterpolationInterpolation
• Interpolation is the creation of new data points from a set of known points.
• For example, a scatter of points on a graph. From the given points you can calculate the line which has the closest fit
![Page 16: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/16.jpg)
16
InterpolationInterpolation• The line could take different forms. For example:
• a straight line which passes through all of the points
• some kind of curve which appears to be a close fit but is allowed to miss the points
![Page 17: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/17.jpg)
17
InterpolationInterpolation
• Interpolation is the operation whereby you capture the essence of a set of data whilst leaving out the noise.
• Interpolation is carried out by creating a function.
• A function "in mathematics, [is] an expression, rule, or law that defines a relationship between one variable (the independent variable) and another variable (the dependent variable)." Encyclopædia Britannica
• So a function takes an input and calculates an output according to some mathematical rule or operation.
![Page 18: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/18.jpg)
18
InterpolationInterpolation
• Set of points. Want to draw a line through them, but we want this to be a aesthetically pleasing curve.
• Need to calculate points in between our known points. This method is know as interpolation.
• Interpolation means to take a set of discrete points at given intervals and generate the continuous function that passes through the points.
• Laurent will do interpolation with you in the context of animation.
![Page 19: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/19.jpg)
19
Linear InterpolationLinear Interpolation
• Linear interpolation is usual abbreviated to lerp.
• By using the parametric line equation you can calculate any point along the line.
)()( 010 PPtPtL
10
100
010
010
)1(
)()(
tPPt
tPtPP
tPtPP
PPtPtL
• Often rearranged into the following form:
![Page 20: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/20.jpg)
20
Polynomial interpolationPolynomial interpolation
• It is also possible to use polynomial interpolation.
• A polynomial expression is an expression involving a sum of powers.
• So simply interpolation using a polynomial.
• Produces interesting curves, for example curves which are irregular, which perform abrupt changes in direction, or even form knots.
![Page 21: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/21.jpg)
21
Topic 4Topic 4
Path Smoothing & Splines
![Page 22: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/22.jpg)
22
Path SmoothingPath Smoothing
• There are many ways to interpolate data. I will introduce a method of generating a curve called the Catmull-Rom spline.
• I will quickly pass over how it does this, but essentially you generate tangents based on the position of the sample points.
• For more details see Van Verthe section 9.6 and Rabin, "A* Aesthetic Optimizations", Games Gems.
![Page 23: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/23.jpg)
23
Catmull-Rom splineCatmull-Rom spline
![Page 24: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/24.jpg)
24
Catmull-Rom splineCatmull-Rom spline• Need four points.
• The curve is derived for the line between the second and third points.
• The line is calculated as a sequence of discrete locations.
• The calculation is carried out for each component of the four points.
• Bicubic polynomial.
2)(
23 DCtBtAttL
![Page 25: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/25.jpg)
25
Catmull-Rom splineCatmull-Rom spline
• Where A, B, C and D are:
2
31
4321
4321
2
)(
)452(
)33(
pD
ppC
ppppB
ppppA
2)(
23 DCtBtAttL
![Page 26: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/26.jpg)
26
Path SmoothingPath Smoothing
• As with parametric line equations, in practice you will express each of the x, y and z components separately (cf. slide 8 and the examples given on slides 10 - 13.)
![Page 27: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/27.jpg)
27
ExampleExample
• Given 4 points (1, 2), (2, 4), (4, 3) and (5, 6).
• Do the calculation first for x:
2*2
)41(
)54*42*51*2(
)54*32*31(
D
C
B
A
2
31
4321
4321
2
)(
)452(
)33(
pD
ppC
ppppB
ppppA
42*2
3)41(
3)516102(
2)51261(
D
C
B
A
![Page 28: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/28.jpg)
28
ExampleExample
• Now plug this into the equation.
• If we want the mid-point between B and C then t = 0.5
42*2
3)41(
3)516102(
2)51261(
D
C
B
A
625.2)5.0(2
25.5)5.0(
2
475.075.025.0)5.0(
2
45.0*325.0*3125.0*2)5.0(
2
45.0*35.0*35.0*2)5.0(
2)5.0(
23
23
L
L
L
L
L
DCtBtAtL
![Page 29: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/29.jpg)
29
Catmull-Rom splineCatmull-Rom spline
• You don't need to derive all of the points of the curve.
• An efficiency gain can be made by using predetermined intervals. This allows you to pre-calculate the value of t.
-0.0703125*+0.8671875*+0.2265625*+-0.0234375* 4321 pppp
-0.0234375*+0.2265625*+0.8671875*+-0.0703125* 4321 pppp
-0.0625*+0.5625*+0.5625*+-0.0625* 4321 pppp
• Quarter interval:
• Half interval:
• Three quarter interval:
![Page 30: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/30.jpg)
30
Catmull-Rom splineCatmull-Rom spline
• In order to derive the line between the second and third points (the middle) use all four points.
• In order to derive the line between the first and second points (the first third) use the first points twice, i.e. p1 and p2 are the same.
• In order to derive the line between the third and last points (the last third) use the last points twice, i.e. p3 and p4 are the same.
![Page 31: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/31.jpg)
31
Characteristics of Catmull-Characteristics of Catmull-Rom splineRom spline
• The curve passes through all of the points.
• It is reasonably efficient.
• The line is continuous.
![Page 32: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/32.jpg)
32
Bézier curveBézier curve
• There are a number of other splines: Hermite splines, B-Splines, etc.
• A commonly used one is the Bézier spline.
• As with all of the splines, the Bézier spline uses polynomial interpolation. A cubic Bézier curve is give using the following forumula:
))1(3)1(3)1()( 43
32
22
13 ptpttpttpttL
![Page 33: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/33.jpg)
33
Characteristics of Catmull-Characteristics of Catmull-Rom splineRom spline
• The curve passes through all of the points.
• It is reasonably efficient.
• The line is continuous.
![Page 34: 1 CO2301 - Games Development 1 Week 12 Interpolation, Path Smoothing & Splines Gareth Bellaby.](https://reader030.fdocuments.net/reader030/viewer/2022032415/56649f055503460f94c1a08f/html5/thumbnails/34.jpg)
34
Characteristics of Bézier Characteristics of Bézier splinespline
• The curve touches the first and last points.
• The curve is within the convex hull of the control points.