Aalto CS-C3100 Computer Graphics, Fall 2016

Similar documents
Computer Animation II

CS354 Computer Graphics Rotations and Quaternions

Orientation & Quaternions

Computer Animation Fundamentals. Animation Methods Keyframing Interpolation Kinematics Inverse Kinematics

CS612 - Algorithms in Bioinformatics

Quaternions and Rotations

Animation. Keyframe animation. CS4620/5620: Lecture 30. Rigid motion: the simplest deformation. Controlling shape for animation

12.1 Quaternions and Rotations

Visual Recognition: Image Formation

Quaternions and Rotations

CS 445 / 645 Introduction to Computer Graphics. Lecture 21 Representing Rotations

Animating orientation. CS 448D: Character Animation Prof. Vladlen Koltun Stanford University

Visualizing Quaternions

3D Rotations and Complex Representations. Computer Graphics CMU /15-662, Fall 2017

Quaternions and Rotations

Quaternions and Rotations

CALCULATING TRANSFORMATIONS OF KINEMATIC CHAINS USING HOMOGENEOUS COORDINATES

Animation. CS 4620 Lecture 32. Cornell CS4620 Fall Kavita Bala

CMSC 425: Lecture 6 Affine Transformations and Rotations

Rotations in 3D Graphics and the Gimbal Lock

Part II: OUTLINE. Visualizing Quaternions. Part II: Visualizing Quaternion Geometry. The Spherical Projection Trick: Visualizing unit vectors.

3D Kinematics. Consists of two parts

Motivation. Parametric Curves (later Surfaces) Outline. Tangents, Normals, Binormals. Arclength. Advanced Computer Graphics (Fall 2010)

3D Transformations and Complex Representations. Computer Graphics CMU /15-662, Fall 2016

Vector Algebra Transformations. Lecture 4

Geometric Transformations

Transformations: 2D Transforms

Transformations Week 9, Lecture 18

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

IMAGE-BASED RENDERING AND ANIMATION

METR 4202: Advanced Control & Robotics

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

3D Transformations. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 11

Quaternion Rotations AUI Course Denbigh Starkey

Animation. CS 4620 Lecture 33. Cornell CS4620 Fall Kavita Bala

Visualizing Quaternions

Quaternions & Rotation in 3D Space

3D Transformations World Window to Viewport Transformation Week 2, Lecture 4

MTRX4700 Experimental Robotics

Lecture Note 3: Rotational Motion

Applications of Dual Quaternions in Three Dimensional Transformation and Interpolation

3D Transformations. CS 4620 Lecture 10. Cornell CS4620 Fall 2014 Lecture Steve Marschner (with previous instructors James/Bala)

Fundamentals of Computer Animation

3D Modelling: Animation Fundamentals & Unit Quaternions

CS184: Using Quaternions to Represent Rotation

2D/3D Geometric Transformations and Scene Graphs

Quaternions and Euler Angles

ME 597: AUTONOMOUS MOBILE ROBOTICS SECTION 2 COORDINATE TRANSFORMS. Prof. Steven Waslander

Quaternions and Exponentials

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Linear algebra deals with matrixes: two-dimensional arrays of values. Here s a matrix: [ x + 5y + 7z 9x + 3y + 11z

Animation and Quaternions

Autonomous Navigation for Flying Robots

Animation Curves and Splines 2

Today. Parity. General Polygons? Non-Zero Winding Rule. Winding Numbers. CS559 Lecture 11 Polygons, Transformations

Rotation and Orientation: Fundamentals. Perelyaev Sergei VARNA, 2011

θ x Week Date Lecture (M: 2:05p-3:50, 50-N202) 1 23-Jul Introduction + Representing Position & Orientation & State 2 30-Jul

CS770/870 Spring 2017 Quaternions

Chapter 3 : Computer Animation

CS 475 / CS 675 Computer Graphics. Lecture 16 : Interpolation for Animation

Rotation with Quaternions

Rotations (and other transformations) Rotation as rotation matrix. Storage. Apply to vector matrix vector multiply (15 flops)

Animation. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 4/23/07 1

2D and 3D Transformations AUI Course Denbigh Starkey

Animations. Hakan Bilen University of Edinburgh. Computer Graphics Fall Some slides are courtesy of Steve Marschner and Kavita Bala

Why animate humans? Why is this hard? Aspects of the Problem. These lectures. Animation Apreciation 101

Advanced Computer Graphics Transformations. Matthias Teschner

a a= a a =a a 1 =1 Division turned out to be equivalent to multiplication: a b= a b =a 1 b

Coordinate Frames and Transforms

To do this the end effector of the robot must be correctly positioned relative to the work piece.

For each question, indicate whether the statement is true or false by circling T or F, respectively.

Transforms. COMP 575/770 Spring 2013

Animation. Traditional Animation Keyframe Animation. Interpolating Rotation Forward/Inverse Kinematics

Inertial Measurement Units II!

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

Fundamentals of Computer Animation

Fundamentals of 3D. Lecture 3: Debriefing: Lecture 2 Rigid transformations Quaternions Iterative Closest Point (+Kd-trees)

Transformation. Jane Li Assistant Professor Mechanical Engineering & Robotics Engineering

Rotation parameters for model building and stable parameter inversion in orthorhombic media Cintia Lapilli* and Paul J. Fowler, WesternGeco.

3D Game Engine Programming. Understanding Quaternions. Helping you build your dream game engine. Posted on June 25, 2012 by Jeremiah van Oosten

GEOMETRIC TRANSFORMATIONS AND VIEWING

Jorg s Graphics Lecture Notes Coordinate Spaces 1

Vector Calculus: Understanding the Cross Product

Reading. Topics in Articulated Animation. Character Representation. Animation. q i. t 1 t 2. Articulated models: Character Models are rich, complex

Quaternion to Euler Angle Conversion for Arbitrary Rotation Sequence Using Geometric Methods

Kinematics, Kinematics Chains CS 685

SUMMARY. CS380: Introduction to Computer Graphics Track-/Arc-ball Chapter 8. Min H. Kim KAIST School of Computing 18/04/06.

Quaternion properties: addition. Introduction to quaternions. Quaternion properties: multiplication. Derivation of multiplication

CT5510: Computer Graphics. Transformation BOCHANG MOON

Representations and Transformations. Objectives

1 Historical Notes. Kinematics 5: Quaternions

animation computer graphics animation 2009 fabio pellacini 1 animation shape specification as a function of time

animation computer graphics animation 2009 fabio pellacini 1

CS230 : Computer Graphics Lecture 12: Introduction to Animation. Tamar Shinar Computer Science & Engineering UC Riverside

Introduction to quaternions. Mathematics. Operations

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

Working With 3D Rotations. Stan Melax Graphics Software Engineer, Intel

Coordinate Transformations. Coordinate Transformation. Problem in animation. Coordinate Transformation. Rendering Pipeline $ = $! $ ! $!

CS 130 Final. Fall 2015

Transcription:

Aalto CS-C3100 Computer Graphics, Fall 2016 Representation and Interpolation of Wikipedia user Blutfink Rotations...or, adventures on the 4D unit sphere Jaakko Lehtinen with lots of slides from Frédo Durand 1

Today s Plan What is a rotation? Some simple rotation representations 3x3 orthogonal matrix axis-angle ( exponential map ) Euler angles Limitations Quaternions Warmup: 2D rotations and complex numbers Spherical linear interpolation (slerp) Representing rotations using quaternions 2

Today s Plan What is a rotation? Some simple rotation representations 3x3 orthogonal matrix axis-angle ( exponential map ) Euler angles Limitations Quaternions Warmup: 2D rotations and complex numbers Spherical linear interpolation (slerp) Representing rotations using quaternions Rotation Survival Guide: What to do in practice 3

Orientations are Everywhere Euclidean transforms Preserves distances Preserves angles Rigid / Euclidean Identity Translation Rotation 4

Orientations are Everywhere In an articulated character, each joint is characterized by its degrees of freedom (dof) Usually rotation about one, two or three axes 1 DOF: knee 2 DOF: wrist 3 DOF: arm 5

What is an Orientation? 6

What is an Orientation? Most intuitive view: orthogonal coordinate system ȳ x z 7

What is an Orientation? Most intuitive view: orthogonal coordinate system ȳ Orthogonality: x k xk = kȳk = k zk =1 x ȳ =0 z x z =0 ȳ z =0 8

What is an Orientation? Most intuitive view: orthogonal coordinate system ȳ x Put axes as columns in 3x3 matrix: M = 0 1... B @ x ȳ z C A... z then orthogonality,.? 9

What is an Orientation? Most intuitive view: orthogonal coordinate system ȳ x Put axes as columns in 3x3 matrix: M = 0 1... B @ x ȳ z C A... z then orthogonality, M T M = I 10

What is an Orientation? Most intuitive view: orthogonal coordinate system ȳ x M = Why? 0 1... B @ x ȳ z C A... z M T M = 0 x x x ȳ 1 x z @ ȳ x ȳ ȳ ȳ z A z x z ȳ z z 11

But also: Orientation is Rotation 12

Rotation is Orientation Euler s Rotation Theorem: All pairs of 3D orthogonal (Cartesian) coordinate systems that share a common origin are related through a rotation about some fixed axis. In other words, you can orient any orthogonal coordinate frame with any other using such a rotation. 13

Rotation is Orientation Euler s Rotation Theorem: All 3D orthogonal (Cartesian) coordinate systems that share a common origin are related through a rotation about some fixed axis. In other words, you can orient any orthogonal coordinate frame with any other using such a rotation. Consequence: Orientation is really the same as rotation This is because you can get to any orientation from the identity transform using a rotation. 14

Euler s Rotation Theorem Orientation 1 15

Euler s Rotation Theorem Orientation 1 Orientation 2 16

Euler s Rotation Theorem Orientation 1 Orientation 2 They are related by a rotation about this axis 17

Euler s Rotation Theorem Orientation 1 Orientation 2 They are related by a rotation about this axis 18

Euler s Rotation Theorem Orientation 1 Orientation 2 They are related by a rotation about this axis 19

Rotation is Orientation Euler s Rotation Theorem: All 3D orthogonal (Cartesian) coordinate systems that share a common origin are related through a rotation about some fixed axis. In other words, you can orient any orthogonal coordinate frame with any other using such a rotation. Consequence: Orientation is really the same as rotation This is because you can get to any orientation from the identity transform using a rotation. This is not really surprising, because rotations form a group, remember? Rotation A followed by rotation B is a new rotation C 20

Plane Rotations How many degrees of freedom? (origin really stays fixed) 21

2D (Plane) Rotations How many degrees of freedom? θ 1 DOF, just one rotation angle 22

3D Rotations How many degrees of freedom? 23

3D Rotations How many degrees of freedom? 3 degrees of freedom (? 2D only had 1 ) direction of rotation (2D) and angle (1D) Only have to care for angle 0 < θ < π Why? When over π, negate axis, take angle 2π - θ θ 24

3D Rotations How many degrees of freedom? 3 degrees of freedom direction of rotation (2D) and angle (1D) Only have to care for angle 0 < θ < π Why? When over π, negate axis, take angle 2π - θ Because orientations and rotations are basically the same, this means orientations are also 3D. θ 25

What is a Rotation? Axis-angle view (as above): Rotation about an axis v by angle θ Can also encode rotation in one 3D vector ( rotation vector ) r = θv, where θ is the angle and v is a unit vector (the axis) Origin is identity, length of vector encodes angle Points inside the sphere of radius π then correspond to orientations (Namedropping: The exponential map ) 26

What is a Rotation? Axis-angle view (as above): Rotation about an axis v by angle θ Can also encode rotation in one 3D vector ( rotation vector ) r = θv, where θ is the angle and v is a unit vector (the axis) Origin is identity, length of vector encodes angle Points inside the sphere of radius π then correspond to orientations (Namedropping: The exponential map ) Linear algebra view Orthogonal matrix, M T M = I, det(m) = 1 (to rule out reflections) In other words, M has orthonormal columns (and rows), i.e., the columns are basis vectors at right angles Count the DOFs... 27

What is a Rotation? Axis-angle view (as above): Rotation about an axis v by angle θ Can also encode rotation in one 3D vector ( rotation vector ) r = θv, where θ is the angle and v is a unit vector (the axis) Origin is identity, length of vector encodes angle Points inside the sphere of radius π then correspond to orientations (Namedropping: The exponential map ) Linear algebra view Orthogonal matrix, M T M = I, det(m) = 1 (to rule out reflections) In other words, M has orthonormal columns (and rows), i.e., the columns are basis vectors at right angles Overcomplete representation: M has more than 3 entries, meaning that not all matrices are proper rotations (duh) 28

Interpolating Orientations in 3D Critical for animation Given rotation matrices M i and time t i, find M(t) such that M(t i )=M i Problem reduces to question: How do you morph between two rotations? t=t3 v t=t1 u n t=t2 M(t) = ux(t) vx(t) nx(t) uy(t) vy(t) ny(t) uz(t) vz(t) nz(t) 29

Interpolating Orientations in 3D Critical for animation Given rotation matrices M i and time t i, find M(t) such that M(t i )=M i Problem reduces to question: How do you morph between two rotations? t=t3 Interpolating positions is easy, just use splines v t=t1 u n t=t2 M(t) = ux(t) vx(t) nx(t) uy(t) vy(t) ny(t) uz(t) vz(t) nz(t) 30

First Try Interpolate each matrix entry independently Example: M0 is identity and M1 is 90 degrees around x-axis Is the result a rotation matrix? 31

Rotation Interpolation: Flawed Solution Interpolate each matrix entry independently Example: M0 is identity and M1 is 90 degrees around x-axis Is the result a rotation matrix? No, it does not preserve rigidity (angles and lengths) What does it do? 32

Are Rotations Simply Vectors, Then? Axis-angle: Rotation about an axis (3 DOF) Can encode rotation in one 3D vector r = θv, where θ is the angle and v is a unit vector Origin is identity All good? Let s think about θv, (θ+n2π)v, (2π-θ)(-v)? n2πv, in particular r = 2πv? θ 33

Are Rotations Simply Vectors, Then? Axis-angle: Rotation about an axis (3 DOF) Can encode rotation in one 3D vector r = θv, where θ is the angle and v is a unit vector Origin is identity All good? Let s think about θv, (θ+n2π)v, (2π-θ)(-v)? n2πv, in particular r = 2πv? There are infinitely many 3D axis-angle vectors that correspond to the same rotation. E.g., the whole ball r = 2π is the identity. Things are relatively OK if we stay within the sphere of radius π. θ 34

Another Try: Rotation Angles An Euler angle is a rotation about a single coordinate axis performed (e.g.) in the sequence Z-Y-Z Corresponds to a gimbal Such a sequence of 3 can get you to any orientation Can also use a sequence of rotations around X-Y-Z Roll, pitch and yaw (perfect for flight simulation) http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf b a a b a c c c b = c b a b a c 35

Another Try: Rotation Angles An Euler angle is a rotation about a single coordinate axis performed (e.g.) in the sequence Z-Y-Z Corresponds to a gimbal Such a sequence of 3 can get you to any orientation Can also use a sequence of rotations around X-Y-Z Roll, pitch and yaw (perfect for flight simulation) Problems: Bad interpolation Gimbal lock http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf b a a b a b = a c a c c b c b c 36

Gimbal Lock Two or more axis align resulting in a loss of rotation degrees of freedom. http://en.wikipedia.org/wiki/euler_angles http://en.wikipedia.org/wiki/gimbal_lock http://www.fho-emden.de/~hoffmann/gimbal09082002.pdf 37

Video See here: http://www.youtube.com/v/ zc8b2jo7mno&start=32&end=190&version=3 38

Fundamental Problem The space of rotations ( the rotation group ) is not Euclidean If you increase the rotation angle, you end up where you started (Buzzword: The topology of the rotation group is that of the projective space RP 3 ) 39

Fundamental Problem The space of rotations ( the rotation group ) is not Euclidean If you increase the rotation angle, you end up where you started (Buzzword: The topology of the rotation group is that of the projective space RP 3 ) Even though the space is 3D, rotations cannot be represented in R 3 without kinks or multiple-valuedness Euler angles are really really nasty (gimbal lock, bad interpolation, cannot be composed easily) Axis-angle is multiple-valued, doesn t interpolate nicely without special considerations, cannot be easily composed 3x3 matrices are redundant and don t interpolate nicely, but can be composed easily (matrix multiplication) 40

Demo Click here to see a screen capture movie 41

Questions? 42

Let s Turn to Interpolation Problem reduces to question: How do you morph between two rotations? t=t3 v t=t1 u n t=t2 M(t) = ux(t) vx(t) nx(t) uy(t) vy(t) ny(t) uz(t) vz(t) nz(t) 43

Desirable Properties for Interpolation Remember Euler s theorem: All orientations A, B are related by a rotation R around an axis v by an angle θ: B = AR. R can be represented as r = θv Interpolated orientation should rotate around v with constant speed, starting from zero angle. 44

Recipe for Axis-Angle Interpolation Remember Euler s theorem: All orientations A, B are related by a rotation R around an axis v by an angle θ: B = AR. R can be represented as r = θv Interpolated orientation should rotate around v with constant speed, starting from zero angle. Axis-angle interpolation how-to: Compute R as A -1 B Extract axis-angle representation r from R (how to in a while) Interpolate linearly between zero and r to yield r(t), i.e., r(t) = tr Convert r(t) back to matrix R(t) Get final orientation by computing AR(t) 45

Interpolation Using Axis-Angle This works because the interpolated rotation vector starts at zero (identity) and always points to the same direction r r(t) = tr, remember equivalently, the axis stays fixed and the angle changes linearly I.e., in the local coordinate system of A, the rotation axis direction stays fixed, only angle changes. 46

Interpolation Using Axis-Angle This works because the interpolated rotation vector starts at zero (identity) and always points to the same direction r r(t) = tr, remember equivalently, the axis stays fixed and the angle changes linearly I.e., in the local coordinate system of A, the rotation axis direction stays fixed, only angle changes. Remember that A and B are both rotations, too. However if you represent them as vectors ra and rb using axisangle, and interpolate the corresponding 3D vectors linearly, this does NOT yield the correct result. It interpolates the orientations, but not around v at unit speed. (Why not? It s kind of deep. Let s not go there.) In contrast, what we did on previous slide: Axis-angle interpolation of the relative rotation R between A and B. 47

Axis-angle to Matrix Given unit axis v, angle θ, compute rotation matrix R This is a restatement of Rodrigues formula v + = 0 v 3 v 2 v 3 0 v 1 v 2 v 1 0 This matrix corresponds to cross product with v. R = I cos + (1 cos )vv T v + sin If represented as r=θv, must normalize and compute length first, and watch out for zeros Outer product 48

Matrix to Axis-Angle Given rotation matrix R, compute axis v and angle θ = cos 1 ((R 11 + R 22 + R 33 1)/2) v 1 =(R 32 R 23 )/(2 sin ) v 2 =(R 13 R 31 )/(2 sin ) v 3 =(R 21 R 12 )/(2 sin ) Derived using the fact that the rotation axis is the only real eigenvector of a rotation matrix Don t worry about it 49

Recap You can t identify orientations/rotations with 3D points and have all of Nice interpolation Smoothness (no gimbal lock) Simple composition of rotations No complicated multiple-valuedness (You can, however, interpolate relative changes in orientation using the axis-angle representation.) Next: Quaternions, a 4D construction that does exactly what we want, both absolutely and relatively We ll represent rotations using unit quaternions, i.e., points lying on the 4-dimensional unit hypersphere (simple, eh?) 50

Questions? 51

1D Sphere and Complex Plane Represent 2D rotation by point on unit circle 2 coordinates but only 1 DOF And we can say that the 2D plane is the complex plane Orientation = complex argument Unit circle = complex magnitude is 1 Interestingly, composition of rotation " complex multiplication Trivial with exponential notation re iθ θ 0 θ 1 q0 q1 Remember homogeneous coordinates? Adding a dimension can make life easier. Interpolation of angle is easy: Just slide the point along the circle. 52

Velocity Issue: lerp vs. slerp Linear Interpolation (lerp) between the 2D points interpolates the straight line between the two orientations Renormalize q(t) to lie on the circle again lerp motion does not have uniform angular velocity keyframes Aalto lerp CS-C3100 Fall 2016 - Lehtinen 53

Velocity Issue: lerp vs. slerp Linear Interpolation (lerp) between the 2D points interpolates the straight line between the two orientations lerp motion does not have uniform angular velocity Spherical Linear Interpolation (slerp) interpolates along the arc lines by adding a sine term: where ω is the angle between q 0 and q 1 We still interpolate in 2D plane, but along an arc Silly to make things so complex in 2D, but will be critical in 3D keyframes lerp slerp interpolate along arc line rather than secant 54

Slerp derivation (2D) Frame c 0, v v =[c 1 -(c 1.c 0 )c 0 ]/sin ω =[c 1 -cos ω c 0 ]/sin ω P(t) in frame c 0, v: (cos ωt, sin ωt) That is P(t)=c 0 cos ωt+v sin ωt =c 0 cos ωt +sin ωt [c 1 -cos ω c 0 ]/sin ω =c 0 [cos ωt -sin ωt cos ω/sin ω]+ c 1 sin ωt /sin ω =c 0 [cos ωt sin ω -sin ωt cos ω]/sin ω+ c 1 sin ωt /sin ω =c 0 sin (ω ωt) /sin ω+ c 1 sin ωt /sin ω ω θ 0 c 0 c 1 θ 1 v P(t) [remember your trigonometry] 55

Velocity Issue: lerp vs. slerp Linear Interpolation (lerp) between the 2D points interpolates the straight line between the two orientations Brain teasers lerp motion Can does not you have uniform prove angular that... velocity Spherical Linear Interpolation (slerp) interpolates along the arc lines by adding a sine term: 1) slerp produces a constant-speed curve? 2) the result is always a unit vector when where ω is the angle between q 0 and q 1 We still interpolate in 2D plane at unit speed, but along an arc Silly to make things so complex in 2D, but will be critical in 3D q0 and q1 are unit vectors? (Hint for 1: Differentiate w.r.t. t, take magnitude, trig identities General hints: trig identities, interpolate q0 and q1 are unit, definition of ω) along arc line rather than secant keyframes Aalto lerp CS-C3100 Fall 2016 - Lehtinen slerp 56

Questions? Recap plane rotation in 2D: a point on unit circle complex number interpretation use slerp for uniform speed works on the sphere in any dimension θ 1 θ 0 57

2-DOF Orientation Can represent by 2 angles But this is messy because modulo 2π and pole... q0 q1 58

2-DOF Orientation Can represent by 2 angles But this is messy because modulo 2π and pole... Solution: Embed 2-sphere in 3D Interpolate 3D points on the 2-sphere along great circles When done interpolating, convert the point back to angles Use slerp for uniform velocity & to stay on sphere Note that it s still a 1D problem along the great circle q 0 and q1 are now 3D points q0 q1 59

3 DOF Quaternions Use the same principle interpolate on higher-dimensional sphere use slerp formula to get uniform angular velocity, stay on 3-sphere 3-sphere embedded in 4D More complex, harder to visualize A point on 3-sphere corresponds to an 3D orientation 60

Quaternions: Hypercomplex Numbers Due to Hamilton (1843) Can be defined like complex numbers but with 4 coordinates d+ai+bj+ck One real part (d), three imaginary ones. Based on three different roots of -1: i 2 = j 2 = k 2 = -1 and weird multiplication rules ij = k = -ji jk = i = -kj ki = j = -ik http://en.wikipedia.org/wiki/william_rowan_hamilton 61

Quaternions: Hypercomplex Numbers Due to Hamilton (1843) Can be defined like complex numbers but with 4 coordinates d+ai+bj+ck One real part (d), three imaginary ones. Or defined with an imaginary part v that is a 3D vector: (s, v) simpler notation http://en.wikipedia.org/wiki/william_rowan_hamilton 62

Quaternions: Rotation Representation Rotations represented by unit vectors in 4D Right-hand rotation of θ radians about v: q = (cos(θ/2); v sin(θ/2)), v Notes unit quaternions are restricted to the unit 3-sphere in 4D (by definition of the unit sphere) q & -q represent the same orientation Why? (Hint: Graphs of sine and cosine, what happens to angle when axis flips if rotation is to remain same?) Resembles axis-angle, but with the sines and cosines 63

Quaternions: Identity Rotations represented by unit vectors in 4D Right-hand rotation of θ radians about v: q = (cos(θ/2); v sin(θ/2)), v Identity orientation? 64

Quaternions: Identity Rotations represented by unit vectors in 4D Right-hand rotation of θ radians about v: q = (cos(θ/2); v sin(θ/2)), v Identity orientation? θ is zero => scalar part = 1 Axis can be arbitrary, but since we want a unit quaternion => q = (1, 0) BUT: Can also take q = (-1, 0) q & -q represent the same rotation, remember 65

Question? Recap: Rotation in 2D embedded on unit circle complex number interpretation slerp for uniform speed works on the sphere in any dimension Quaternions 4D extension of complex numbers rotations = unit quaternions (on 3-sphere) (cos(θ/2); v sin(θ/2)) : rotation of θ around v q q v 66

Interpolating Rotations Given two unit quaternions, we want to interpolate Use slerp Works on the sphere in any dimension Where ω is still the angle between q0 and q1 like in 2D Note: This is again a linear combination of q 0 and q1 Quaternion slerp gives exactly the desired unitspeed transition between the orientations represented by q0 and q1 And does so without any of the problems we saw with axis-angle, Euler, or matrices 67

Linear Combination of Quaternions Just like vectors, just like complex numbers Addition: Componentwise (s, v) + (s, v ) = (s+s, v+v ) Multiplication by scalar t(s,v)=(ts, tv) 68

You Might Need To Invert q Recall: q & -q represent the same rotation Given q0 and q1, test the angle (in 4D) If dot product of q 0 and q1 is negative, they are on opposite sides of the hypersphere, and interpolation will take the longer route (red) If this is the case, just use -q1 instead of q1 q0 q1 69

Slerp: Sanity Check Interpolate between identity (q0) and rotation around v (q1) q0=(1; 0) q1 = (cos(θ/2); v sin(θ/2)) [ (1, 0) sin((1-t) θ) + (cos(θ/2); v sin(θ/2)) sin (tθ) ]/sin(θ) = (sin(θ-tθ)+cos(θ/2)sin(tθ); v sin(θ/2) sin (tθ))/sin(θ) See if you can use your trig skillz to get from the sin (θ-tθ)=sinθ cos(tθ) - cosθ sin(tθ) sinθ cos(tθ)-cosθ sin(tθ)+cos(θ/2)sin(tθ) above to the goal cos(tθ)+cos(θ/2)-sin(tθ) cosθ/sinθ cos^2(tθ/2)-sin^2(tθ/2) (cos(θt/2); v sin(θt/2)) 70

Problem with Splines Slerp only works to interpolate between two positions For splines, we need to blend more, typically 4 (for cubics) t=t3 v u t=t2 t=t1 n 71

De Casteljau Construction Remember what we did with planar cubic Bézier curves Works to construct a point at any t Only requires interpolation between pairs of points Do slerp between pairs of key quaternions q3 slerp(q2, q3, t) q2 t t slerp t slerp t slerp t slerp(q3, q4, t) slerp(q1, q2, t) t q1 q4 72

This is an easy extra in Assignment 2 73

Extensions Better interpolation E.g. minimize acceleration, velocity constraint http://www.gg.caltech.edu/stc/rr_sig97.html http://portal.acm.org/citation.cfm? id=218486&dl=acm&coll=portal&cfid=1729050&cftoken=744188 64 http://portal.acm.org/citation.cfm? id=134086&dl=acm&coll=portal&cfid=1729050&cftoken=744188 64 From Kim et al. 1995 74

Questions? Recap 1D rotation: unit complex number slerp 3D rotation: unit quaternions q = (cos(θ/2); v sin(θ/2)) represents rotation of θ around axis v slerp just works directly Splines constructed with De Casteljau Demos at http://www.visualizingquaternions.com/companions/ 9780120884001/vq/index.html 75

Cookbook Recipe You need matrices to draw (e.g. OpenGL) General approach for 3 DOF rotations Store keyframe orientations as quaternions Interpolate between them using slerp (pairwise) or slerp + De Casteljau (splines) Convert to quaternion to matrix Profit. (Or, store matrices, convert to quaternions for interpolation, then convert back.) 76

Cookbook Recipe You need matrices to draw (e.g. OpenGL) General approach for 3 DOF rotations Store keyframe orientations as quaternions Interpolate between them using slerp (pairwise) or slerp + De Casteljau (splines) Convert to quaternion to matrix Profit. Often need to convert from matrix to quaternion. Next: Conversion to/from matrices. 77

Quaternion to Rotation Matrix Quaternion (q0, q1, q2, q3) corresponds to matrix 1 2q2 2 2q3 2 2(q 1 q 2 q 3 q 0 ) 2(q 1 q 3 + q 2 q 0 ) 2(q 1 q 2 + q 3 q 0 ) 1 2q1 2 2q3 2 2(q 2 q 3 q 1 q 0 ) 2(q 1 q 3 q 2 q 0 ) 2(q 1 q 0 + q 2 q 3 ) 1 2q1 2 2q2 2 Similar to Rodrigues rotation formula but recall that quaternions use θ/2 After conversion, you can combine rotations and other affine/projective transforms 78

3x3 Orthonormal Matrix to Quaternion More challenging (first of all, not all Ms are rotations) if M is a rotation, trace(m)>0 then you get quaternion (s, x, y, z) through: s = sqrt (1 + M 11 + M22 + M33) /2 x = (M 23 - M32) / ( 4 * s) y = (M31 - M13) / ( 4 * s) z = (M12 - M21) / ( 4 * s) if trace(m)<0, need some permutation/sign changes Code at e.g. http://www.euclideanspace.com/maths/geometry/rotations/ conversions/matrixtoquaternion/index.htm http://www.intel.com/cd/ids/developer/asmo-na/eng/293748.htm http://vamos.sourceforge.net/matrixfaq.htm http://vamos.sourceforge.net/matrixfaq.htm#q48 79

General Conversion Resource http://en.wikipedia.org/wiki/rotation_representation_ %28mathematics%29 80

What about other transforms? What to do if the matrix to be interpolated does not only rotation, but scale, shear, etc.? 81

Non-orthonormal 3x3 matrix Polar decomposition breaks arbitrary matrix M into Rotation Q (+potential reflection) Symmetric positive definite S (anisotropic scale) Extract rotation part Q, interpolate it using quaternions Interpolate S using some other method. Shoemake, K. and Duff, T. 1992. Matrix animation and polar decomposition. In Proceedings of the Conference on Graphics interface '92, pp258-264. http://www.cs.wisc.edu/graphics/courses/838-s2002/papers/polar-decomp.pdf 82

Polar Decomposition Algorithm Given 3x3 Matrix M Compute the rotation factor Q by averaging the matrix with its inverse transpose until convergence: Set Q 0 = M, then Qi+1 = 1/2(Qi+ Qi T ) until Qi+1 Qi 0. 83

Questions? Recap 1D rotation: unit complex number slerp 3D rotation: unit 4D quaternions q = (cos(θ/2); v sin(θ/2)) represents rotation of θ around axis v slerp just works directly De Casteljeau for splines Conversion with matrices Polar decomposition if not orthonormal Demos at http://www.visualizingquaternions.com/companions/ 9780120884001/vq/index.html 84

More Quaternion Magic: Multiplication Turns out that quaternion multiplication corresponds to composing rotations That is, q2 = q1q0 is equivalent to first rotating by q0, then q1. ( ; v)( ; v )= ( v v ; v + v + v v ) Multiplication is not commutative (why? cross product) q 1q0 does not equal q0q1 except in special cases Makes sense, rotations are not commutative either Verifications Check the formula, remembering the funky multiplication rules from the definitions. (Or, then just trust me. I m not going to ask you to do this in quiz.) 85

Even More Quaternion Magic: Conjugate and Inverse Let s define a conjugate q* = (θ, -v) Remember complex conjugate? a = x + iy, a* = x - iy Is there an inverse quaternion q -1 such that qq -1 =(1; 0) for unit q? Let s try the conjugate... Again, compare to complex: aa* = x 2 +y 2 = 1 when a is unit length. ( ; v)( ; v )= ( v v ; v + v + v v ) 86

Even More Quaternion Magic: Conjugate and Inverse Let s define a conjugate q* = (θ, -v) Remember complex conjugate? a = x + iy, a* = x - iy Is there an inverse quaternion q -1 such that qq -1 =(1; 0) for unit q? Let s try the conjugate... Again, compare to complex: aa* = x 2 +y 2 = 1 when a is unit length. Let s see: qq = ( 2 + v v; v v + v v) = (1; 0) Note that this only works for unit q. If not unit, need normalization factor. ( ; v)( ; v )= ( v v ; v + v + v v ) 87

Even More Quaternion Magic: Conjugate and Inverse Let s define a conjugate q* = (θ, -v) Remember complex conjugate? a = x + iy, a* = x - iy Is there an inverse quaternion q -1 such that qq -1 =(1; 0) for unit q? Let s try the conjugate... Again, compare to complex: aa* = x 2 +y 2 = 1 when a is unit length. Let s see: qq = q* = q -1 for unit quaternions ( 2 + v v; v v + v v) = (1; 0) Note that this only works for unit q. If not unit, need normalization factor. ( ; v)( ; v )= ( v v ; v + v + v v ) 88

Inverse & Conjugate: Geometry θ v q = (cos θ/2; sinθ/2 v) represents a rotation of angle θ around v Inverse rotation q -1 : Angle -θ around v Angle θ around v -θ In both cases, leads to (cos θ/2; -sinθ/2 v) q* = (θ, -v), remember 89

Inverse & Conjugates: Matrices What is the inverse of a rotation matrix? 90

Inverse & Conjugates: Matrices What is the inverse of a rotation matrix? The conjugate/transpose matrix For a rotation (or any orthonormal matrix) MT M=I (Formally, to get the conjugate of a complex-valued matrix, take the transpose and the conjugate of each coefficient. But we don t care here.) The notion of conjugation is related between matrices & quaternions Isn t that cool? 91

Even More 4D Magic: Rotating a Point 3D vector p is represented by the quaternion (0, p) To rotate 3D point/vector p by rotation/quaternion q, compute qpq -1 = q(0; p)q -1 92

Even More 4D Magic: Rotating a Point 3D vector p is represented by the quaternion (0, p) To rotate 3D point/vector p by rotation/quaternion q, compute qpq -1 = q(0; p)q -1 In practice, it s better to convert the quaternion to a matrix. You can combine with other linear transformation then 93

That s All For Today Coming up: Computer Animation I 94

Question? 95

Fun: Mandelbrot & Julia set For each pixel at coordinate c 0 series: c n+1 =c n2 +c where c is a constant same for the whole image for Julia sets One image per c c=x+iy for each 2D point for Mandelbrot Set = set of pixels where the series does not diverge Can be colored according to how fast it diverges Julia sets for two different c 0 http://www.geocities.com/capecanaveral/2854/mandelbrot.html 96

Fun: Julia sets in quaternion space Same kind of series, but quaternions instead of complex a slice can be visualized in 3D the full 4D thing leads to nice animations http://www.devmaster.net/forums/showthread.php?t=4448 97

More Fun Julia Sets in Quaternion space http://aleph0.clarku.edu/~djoyce/julia/explorer.html Pascal Massimino http://skal.planet-d.net/ http://www.chaospro.de/gallery/gallery.php?cat=anim 98