class 05 animation curves and splines 2 - stanford university

27
Animation Curves and Splines 2

Upload: others

Post on 02-May-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: class 05 animation curves and splines 2 - Stanford University

Animation Curves and Splines 2

Page 2: class 05 animation curves and splines 2 - Stanford University

Animation Homework

• Set up a simple avatar• E.g. cube/sphere (or square/circle if 2D)• Specify some key frames (positions/orientations)• Associate a time with each key frame • Create smooth animations for the avatar movement• does it pass through or just near the key frames and

positions?• Save the canned animations for later use• Provide a couple of examples• A crawling bug, a bouncing ball, etc…• Use unity…

Thursday Animation

& Unity

Page 3: class 05 animation curves and splines 2 - Stanford University

Bezier Curves

Page 4: class 05 animation curves and splines 2 - Stanford University

Bezier Curves

• Specify control points instead of derivatives

Page 5: class 05 animation curves and splines 2 - Stanford University

Bezier Curves

• A Bezier curve is defined by a set of control points 𝐏𝟎, …, 𝐏𝐧 where 𝐧 determines the order of a Bezier curve

• Start from a linear Bezier curve based on two control points, and build recursively

• A linear Bezier curve is a straight line

, 0 1( ) (1 )t t t= - +0 1P PP P P

Page 6: class 05 animation curves and splines 2 - Stanford University

• A quadratic Bezier curve is determined by 3 control points 𝐏𝟎, 𝐏𝟏, 𝐏𝟐

Bezier Curves

• The basis functions are quadratic functions

0 1 2 0 1 1 2, , , ,( ) (1 ) ( ) ( )t t t t t= - +P P P P P P PP P P• 𝐏𝐏𝟎,𝐏𝟏,𝐏𝟐(𝑡) is linearly

interpolated on the green line, and the endpoints of the green line lie on linear Bezier curves determined by 𝐏𝟎, 𝐏𝟏 and 𝐏𝟏, 𝐏𝟐respectively

0 1 2

2 2, , 0 1 2( ) (1 ) 2 (1 )t t t t t= - + - +P P PP P P P

Page 7: class 05 animation curves and splines 2 - Stanford University

Bezier Curves

• A cubic Bezier curve is determined by 4 control points

, , , , , , ,( ) (1 ) ( ) ( )t t t t t= - +0 1 2 3 0 1 2 1 2 3P P P P P P P P P PP P P

• 𝐏𝐏𝟎,𝐏𝟏,𝐏𝟐,𝐏𝟑(𝑡) is linearly interpolated on the blue line, and the path of the two end points of the blue line are quadratic Bezier curves determined by 𝐏𝟎, 𝐏𝟏, 𝐏𝟐and 𝐏𝟏, 𝐏𝟐, 𝐏𝟑 respectively

• The basis functions are cubic functions3 2 2 3

, , , 0 1 2 3( ) (1 ) 3 (1 ) 3 (1 )t t t t t t t= - + - + - +0 1 2 3P P P PP P P P P

Page 8: class 05 animation curves and splines 2 - Stanford University

Bezier Curves• Higher order Bezier curves are defined recursively

• The basis functions of an 𝐧𝐭𝐡 order Bezier curve are 𝐧𝐭𝐡 order polynomials

where

, ,..., , ,..., , ,...,( ) (1 ) ( ) ( )t t t t t= - +0 1 n 0 1 n-1 1 2 nP P P P P P P P PP P P

• High order Bezier curves are more expensive to evaluate

• When a complex shape is needed, low order Bezier curves (usually cubic) are connected together

, ,...,0

( ) ( )n

ni i

it B t

=

=å0 1 nP P PP P

( ) (1 )n i n ii

nB t t t

i-æ ö

= -ç ÷è ø

Page 9: class 05 animation curves and splines 2 - Stanford University

Connecting Cubic Bezier Curves

• Want velocity to be continuous

• Need co-linear control points across the junctions

Page 10: class 05 animation curves and splines 2 - Stanford University

C0 Continuity for Bezier Curves

• Points are specified continuously• But tangents are specified discontinuously

Page 11: class 05 animation curves and splines 2 - Stanford University

C1 Continuity for Bezier Curves

• Tangents are specified continuously as well

Page 12: class 05 animation curves and splines 2 - Stanford University

Rotations

Page 13: class 05 animation curves and splines 2 - Stanford University

Rotation Interpolation

• Besides translation, the motion of a rigid object also includes rotation• Consider an axis of rotation (out of the page) and angles of

rotation 𝜶 with respect to that axis

• Would like the object to smoothly change from one orientation to the other

𝛼0𝛼1

Page 14: class 05 animation curves and splines 2 - Stanford University

Rotation Interpolation

Linear interpolation of Angles: 𝛼(𝑡) = 1 − 𝑡 𝛼0 + 𝑡𝛼1

• Need to be mindful of angle limits• Not necessarily the shortest path• Suppose we interpolate from 𝛼0 = 1° to 𝛼1 = 359°• This rotates almost a full circle, although the two angles

are nearly the same

𝛼0𝛼(𝑡) 𝛼1

Page 15: class 05 animation curves and splines 2 - Stanford University

Recall: 2D Rotation MatrixThe columns of the matrix are the new locations of the x and y axes

So set the columns to the desired new locations of the x and y axes

Rotation matrix =

3D is similar…

Page 16: class 05 animation curves and splines 2 - Stanford University

Euler Angles

• Euler angles: • from the original axes (𝒙𝒚𝒛)• α: a rotation around the z-axis (𝒙′𝒚′𝒛′)• β: a rotation around the N-axis (𝒙"𝒚"𝒛")• γ: a rotation around the Z-axis (𝑿𝒀𝒁)• Three angles are applied in this fixed

sequence• N-axis and Z-axis are both moving axes

• Interpolate rotation using Euler angles• Could parameterize each of the angles:

α(t), β(t), γ(t)

𝒙

𝒚

𝒛

𝐍(𝒙C)

𝒚C

(𝒛C)

𝜶

𝜶

(𝒛")(𝒚")

𝜷

(𝒙")

𝜷

𝐙

Page 17: class 05 animation curves and splines 2 - Stanford University

Euler Angles

• Euler angles can lead to artifacts: gimbal lock

Page 18: class 05 animation curves and splines 2 - Stanford University

Question #1LONG FORM:• Summarize how Euler Angles work, and explain gimbal

lock.• List 5 things you plan to do research on in order to learn

more about designing your game (One sentence for each idea).

SHORT FORM• Form clusters (of about size 5-ish?) with at least one

novice gamer in each cluster.• Take turns answering questions that person might have,

and otherwise giving him/her advice.• Write down the best piece of advice you heard.

Page 19: class 05 animation curves and splines 2 - Stanford University

Quaternions

Page 20: class 05 animation curves and splines 2 - Stanford University

• Quaternions are an extension of complex numbers

• The conjugate of a quaternion is defined as

•They are added and subtracted (term by term) as usual.

Quaternions

• Multiplication is defined as follows: (using the table)

q s xi yj zk= + + +

*q s xi yj zk= - - -

1 2 1 2 1 2 1 2 1 2

1 2 1 2 1 2 1 2

1 2 1 2 1 2 1 2

1 2 1 2 1 2 1 2

( , , , )

q q s s x x y y z zs x x s y z z ys y x z y s z xs z x y y x z s

= - - -+ + -- + ++ - +

Page 21: class 05 animation curves and splines 2 - Stanford University

Unit Quaternions as Rotations

• A quaternion can be expressed as a scalar/vector pair:𝑞 = 𝑠, �⃗� �⃗� = (𝑥, 𝑦, 𝑧)

• A unit (length) quaternion can be obtained by dividing through all the elements by:

• Each unit quaternion corresponds to a rotation• For a rotation around a 3D axis of angle , the corresponding

unit quaternion is

• A quaternion multiplied by a nonzero scalar still corresponds to the same rotation (since normalization removes the scalar)

2 2 2 2q s x y z= + + +

n̂ q

ˆ(cos ,sin )2 2

nq q

where

Page 22: class 05 animation curves and splines 2 - Stanford University

• A unit quaternion is equivalent a rotation matrix:

• Rotating a vector by a unit quaternion is faster than using a rotation matrix (a vector can be viewed as a non-unit quaternion with the scalar part set equal to zero)

𝑅otate 𝑢 = 𝑞𝑢𝑞S1

•The inverse of a unit quaternion is simply its conjugate 𝑞∗

•( The inverse of a non-unit quaternion is 𝑞S1 = 𝑞∗/ 𝑞 V )

Unit Quaternions as Rotations

( , , , )s x y z2 2

2 2

2 2

1 2 2 2 2 2 22 2 1 2 2 2 22 2 2 2 1 2 2

y z xy sz xz syxy sz x z yz sxxz sy sx yz x y

æ ö- - - +ç ÷

+ - - -ç ÷ç ÷- + - -è ø

Page 23: class 05 animation curves and splines 2 - Stanford University

Interpolating Unit Quaternions• Unit quaternions can be viewed as points lying on a 4-D

unit sphere:• Interpolating between these points means tracing out a

curve on the surface of this 4-D sphere• This framework allows us to take the shortest path as

represented by an arc on the 4D sphere

( , , , )s x y z

Note: The 3D unit sphere is for illustrating the idea. The unit quaternion sphere is 4D!

Page 24: class 05 animation curves and splines 2 - Stanford University

SLERP• Spherical Linear Interpolation• Linearly interpolate between points and on the unit sphere:

0 1sin(1 ) sin( )sin sin

t tq t q qj jj j-

= +

0 1( ) (1 )q t t q tq= - +

0q 1q

• According to L'Hôpital's rule,

•Therefore, as goes to zero, we get linear interpolation

0 0 0

0 0 0

sin (sin ) coslim lim limsin (sin ) cossin(1 ) (sin(1 ) ) (1 )cos(1 )lim lim lim 1sin (sin ) cos

t t t t t

t t t t t

j j j

j j j

j j jj j j

j j jj j j

® ® ®

® ® ®

¢= = =

¢¢- - - -

= = = -¢

j

Page 25: class 05 animation curves and splines 2 - Stanford University

Angle Between Unit Quaternions

• The angle 𝜑 between two unit quaternions on a 4D sphereis calculated using:

𝜑 = arccos(𝑞0 [ 𝑞1)

with a typical dot-product: 𝑞0 [ 𝑞1 = 𝑠0𝑠1 + 𝑥0𝑥1 + 𝑦0𝑦1 + 𝑧0𝑧1•𝜑 is guaranteed to be between 0, 𝜋

• However, it still does not guarantee the shortest path, because 𝑞 and −𝑞 correspond to the same rotation!

• So, if 𝑞0 [ 𝑞1 is negative, we negate either 𝑞0 or 𝑞1 before applying SLERP to guarantee the shortest path

Page 26: class 05 animation curves and splines 2 - Stanford University

SLERP for Unit Quaternions• A quaternion 𝑞 = (𝑠, �⃗�) can be defined in exponential form

𝑞 = 𝑞 𝑒_̀a = 𝑞 (cos 𝛼 + �̀� sin 𝛼)

where 𝛼and the unit vector �̀� are defined via:𝑠 = 𝑞 cos 𝛼 , �⃗� = �̀� �⃗� = 𝑞 �̀� sin 𝛼

• �̀�is the rotation axis, and 𝛼 equals half of the rotation angle

• The power of a quaternion is then: 𝑞e = 𝑞 e𝑒_̀ae

• Note that the power affects the rotation angle 𝛼, but not the rotation axis �̀�

• Finally, SLERP for unit quaternions is expressed as:𝑆𝐿𝐸𝑅𝑃 𝑞0, 𝑞1; 𝑡 = 𝑞0(𝑞0S1𝑞1) e

Page 27: class 05 animation curves and splines 2 - Stanford University

Question #2LONG FORM:• Briefly explain why we use quaternions for rotations.• Explain why moving rigid bodies use both a linear and an

angular velocities.• Answer the Short Form questions as well…

SHORT FORM• Can you think of a particularly visually interesting rigid

body used in games, movies, or television? • Very briefly describe it.• Explain how it makes use of translations and/or rotations

for visual effects.