Rotations and Quaternions



Similar documents
Lecture 7. Matthew T. Mason. Mechanics of Manipulation. Lecture 7. Representing Rotation. Kinematic representation: goals, overview

Animation (-4, -2, 0 ) + (( 2, 6, -4 ) - (-4, -2, 0 ))*.75 = (-4, -2, 0 ) + ( 6, 8, -4)*.75 = (.5, 4, -3 ).

Fundamentals of Computer Animation

Computing Euler angles from a rotation matrix

3D Tranformations. CS 4620 Lecture 6. Cornell CS4620 Fall 2013 Lecture Steve Marschner (with previous instructors James/Bala)

Vector Math Computer Graphics Scott D. Anderson

Understanding Rotations

Basic Linear Algebra

LINES AND PLANES IN R 3

Rotation Matrices and Homogeneous Transformations

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

Metrics on SO(3) and Inverse Kinematics

Essential Mathematics for Computer Graphics fast

Geometric Transformation CS 211A

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

TWO-DIMENSIONAL TRANSFORMATION

Recall the basic property of the transpose (for any A): v A t Aw = v w, v, w R n.

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

2D Geometric Transformations

ex) What is the component form of the vector shown in the picture above?

Physics 235 Chapter 1. Chapter 1 Matrices, Vectors, and Vector Calculus

Computing Orthonormal Sets in 2D, 3D, and 4D

Vector Algebra. Addition: (A + B) + C = A + (B + C) (associative) Subtraction: A B = A + (-B)

Lecture L3 - Vectors, Matrices and Coordinate Transformations

The Force Table Introduction: Theory:

v 1 v 3 u v = (( 1)4 (3)2, [1(4) ( 2)2], 1(3) ( 2)( 1)) = ( 10, 8, 1) (d) u (v w) = (u w)v (u v)w (Relationship between dot and cross product)

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

Computer Animation. Lecture 2. Basics of Character Animation

Cross product and determinants (Sect. 12.4) Two main ways to introduce the cross product

Math 241, Exam 1 Information.

Lecture 3: Coordinate Systems and Transformations

Solutions to Practice Problems for Test 4

Problem Set 5 Due: In class Thursday, Oct. 18 Late papers will be accepted until 1:00 PM Friday.

Vectors VECTOR PRODUCT. Graham S McDonald. A Tutorial Module for learning about the vector product of two vectors. Table of contents Begin Tutorial

Review B: Coordinate Systems

The Vector or Cross Product

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

CIS 536/636 Introduction to Computer Graphics. Kansas State University. CIS 536/636 Introduction to Computer Graphics

Chapter 6. Linear Transformation. 6.1 Intro. to Linear Transformation

A vector is a directed line segment used to represent a vector quantity.

Solving Simultaneous Equations and Matrices

Vector Algebra CHAPTER 13. Ü13.1. Basic Concepts

Rigid body dynamics using Euler s equations, Runge-Kutta and quaternions.

GCE Mathematics (6360) Further Pure unit 4 (MFP4) Textbook

Unit 3 (Review of) Language of Stress/Strain Analysis

Figure 1.1 Vector A and Vector F

3. INNER PRODUCT SPACES

Unified Lecture # 4 Vectors

Introduction to Computer Graphics Marie-Paule Cani & Estelle Duveau

CS 4204 Computer Graphics

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Solutions to Practice Problems

Geometric Transformations

MATH 304 Linear Algebra Lecture 20: Inner product spaces. Orthogonal sets.

One advantage of this algebraic approach is that we can write down

Dot product and vector projections (Sect. 12.3) There are two main ways to introduce the dot product

Section 9.5: Equations of Lines and Planes

discuss how to describe points, lines and planes in 3 space.

AP Physics - Vector Algrebra Tutorial

Inner Product Spaces

ANALYTICAL METHODS FOR ENGINEERS

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

1 Symmetries of regular polyhedra

13.4 THE CROSS PRODUCT

5.3 The Cross Product in R 3

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Geometric Transformations

Section V.3: Dot Product

LINEAR MAPS, THE TOTAL DERIVATIVE AND THE CHAIN RULE. Contents

animation animation shape specification as a function of time

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

[1] Diagonal factorization

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

Chapter 17. Orthogonal Matrices and Symmetries of Space

How To Draw A 3D Virtual World In 3D Space (Computer Graphics)

Objective: To distinguish between degree and radian measure, and to solve problems using both.

Analysis of Stresses and Strains

Lecture L30-3D Rigid Body Dynamics: Tops and Gyroscopes

Section 1.1. Introduction to R n

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

B2.53-R3: COMPUTER GRAPHICS. NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.

Kinematical Animation

x = + x 2 + x

Equations Involving Lines and Planes Standard equations for lines in space

Lecture L29-3D Rigid Body Dynamics

MODELLING A SATELLITE CONTROL SYSTEM SIMULATOR

MATLAB Workshop 3 - Vectors in MATLAB

APPLICATIONS. are symmetric, but. are not.

Two vectors are equal if they have the same length and direction. They do not

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

Calculation of Azimuth, Elevation and Polarization for non-horizontal aligned Antennas

2.2 Creaseness operator

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

Force on a square loop of current in a uniform B-field.

Chapter. 4 Mechanism Design and Analysis

Orthogonal Projections

Solutions for Review Problems

CS 4620 Practicum Programming Assignment 6 Animation

Cabri Geometry Application User Guide

Transcription:

Uniersity of British Columbia CPSC 414 Computer Graphics Rotations and Quaternions Week 9, Wed 29 Oct 2003 Tamara Munzner 1

Uniersity of British Columbia CPSC 414 Computer Graphics Clipping recap Tamara Munzner 2

Clipping analytically calculating the portions of primities within the iewport Week 9, Wed 29 Oct 03 Tamara Munzner 3

Clipping Lines To Viewport combining triial accepts/rejects triially accept lines with both endpoints inside all edges of the iewport triially reject lines with both endpoints outside the same edge of the iewport otherwise, reduce to triial cases by splitting into two segments Week 9, Wed 29 Oct 03 Tamara Munzner 4

Cohen-Sutherland Line Clipping outcodes 4 flags encoding position of a point relatie to top, bottom, left, and right boundary OC(p1)=0010 OC(p2)=0000 OC(p3)=1001 1010 1000 1001 p1 p3 0010 0000 0001 y=y max 0110 0100 0101 x= x=x min x=x max y=y min Week 9, Wed 29 Oct 03 Tamara Munzner 5 p2

Polygon Clipping not just clipping all boundary lines may hae to introduce new line segments Week 9, Wed 29 Oct 03 Tamara Munzner 6

Sutherland-Hodgeman Clipping basic idea: consider each edge of the iewport indiidually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped Week 9, Wed 29 Oct 03 Tamara Munzner 7

Sutherland-Hodgeman Clipping basic idea: consider each edge of the iewport indiidually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped Week 9, Wed 29 Oct 03 Tamara Munzner 8

Sutherland-Hodgeman Clipping basic idea: consider each edge of the iewport indiidually clip the polygon against the edge equation after doing all edges, the polygon is fully clipped Week 9, Wed 29 Oct 03 Tamara Munzner 9

Sutherland-Hodgeman Clipping edge from s to p takes one of four cases: (blue line can be a line or a plane) inside s outside inside outside inside outside p inside p outside s p s p s p output i output no output i output p output Week 9, Wed 29 Oct 03 Tamara Munzner 10

Uniersity of British Columbia CPSC 414 Computer Graphics Rotations and Quaternions Tamara Munzner 11

Camera Moement Hints change iewing transformation don t try doing this with perspectie xform! methods glulookat direct camera control using rotate/translate camera motion opposite of object motion rotate world by a = orbit camera by -a Week 9, Wed 29 Oct 03 Tamara Munzner 12

Parameterizing Rotations Straightforward in 2D A scalar, θ, represents rotation in plane More complicated in 3D Three scalars are required to define orientation Note that three scalars are also required to define position Objects free to translate and tumble in 3D hae 6 degrees of freedom (DOF) Week 9, Wed 29 Oct 03 Tamara Munzner 13

Representing 3 Rotational DOFs 3x3 Matrix (9 DOFs) Rows of matrix define orthogonal axes Euler Angles (3 DOFs) Rot x + Rot y + Rot z Axis-angle (4 DOFs) Axis of rotation + Rotation amount Quaternion (4 DOFs) 4 dimensional complex numbers Week 9, Wed 29 Oct 03 Tamara Munzner 14

3x3 Rotation Matrix 9 DOFs must reduce to 3 Rows must be unit length (-3 DOFs) Rows must be orthogonal (-3 DOFs) Drifting matrices is ery bad Numerical errors results when trying to gradually rotate matrix by adding deriaties Resulting matrix may scale / shear Gram-Schmidt algorithm will re-orthogonalize Difficult to interpolate between matrices How would you do it? Week 9, Wed 29 Oct 03 Tamara Munzner 15

Rotation Matrix general rotation can be represented by a single 3x3 matrix length presering (isometric) ux u y u reflection presering R = x y orthonormal problem: wx wy w property: rows and columns are orthonormal (unit length and perpendicular to each other) linear interpolation doesn t maintain this property Week 9, Wed 29 Oct 03 Tamara Munzner 16 z z z

Rotation Matrices Not Interpolatable interpolate linearly from +90 to -90 in y 0 0 1 0 0-1 0 1 0 0 1 0-1 0 0 1 0 0 halfway through component interpolation 0 0 0 0 1 0 0 0 0 problem 1: not a rotation matrix anymore! not orthonormal, x flattened out Week 9, Wed 29 Oct 03 Tamara Munzner 17

Euler Angles (θ x, θ y, θ z ) = R z R y R x Rotate θ x degrees about x-axis Rotate θ y degrees about y-axis Rotate θ z degrees about z-axis Axis order is not defined (y, z, x), (x, z, y), (z, y,x) all legal Pick one Week 9, Wed 29 Oct 03 Tamara Munzner 18

Euler Angle Interpolation solution 1: can interpolate angles indiidually problem 2: interpolation between two Euler angles is not unique ex: (x, y, z) rotation (0, 0, 0) to (180, 0, 0) s. (0, 0, 0) to (0, 180, 180) interpolation about different axes are not independent Cartesian coordinates are independent of one another, but Euler angles are not Week 9, Wed 29 Oct 03 Tamara Munzner 19

Interpolation Week 9, Wed 29 Oct 03 Tamara Munzner 20

Interpolation Week 9, Wed 29 Oct 03 Tamara Munzner 21

Euler Angles Problem 3: Gimbal Lock term deried from mechanical problem that arises in gimbal mechanism that supports a compass or a gyro gimbal: hardware implementation of Euler angles (used for mounting gyroscopes and globes) Week 9, Wed 29 Oct 03 Tamara Munzner 22

Gimbal Lock http://www.anticz.com/eularqua.htm Week 9, Wed 29 Oct 03 Tamara Munzner 23

Gimbal Lock Occurs when two axes are aligned Second and third rotations hae effect of transforming earlier rotations If Rot y = 90 degrees, Rot z == -Rot x [demo] Week 9, Wed 29 Oct 03 Tamara Munzner 24

Locked Gimbal Hardware implementation of Euler angles (used for mounting gyroscopes and globes) Week 9, Wed 29 Oct 03 Tamara Munzner 25

Axis-angle Rotation z n=(n x, n y, n z ) θ y x A counter-clockwise (right-handed) rotation θ about the axis specified by the unit ector n=(n x, n y, n z ) Week 9, Wed 29 Oct 03 Tamara Munzner 26

Axis-angle Notation Define an axis of rotation (x, y, z) and a rotation about that axis, θ: R(θ, n) 4 degrees of freedom specify 3 rotational degrees of freedom because axis of rotation is constrained to be a unit ector Week 9, Wed 29 Oct 03 Tamara Munzner 27

Week 9, Wed 29 Oct 03 Tamara Munzner 28 Angular displacement (θ,n) defines an angular displacement of θ about an axis n n n [ ] R θ ] [ ) sin ( cos ) sin ( cos ] [ ) ( R n n R n n = + = + = = = θ θ θ θ θ θ θ θ θ θ θ )sin ( ) cos )(1 ( cos )sin ( )cos ) ( ( ) ( )sin ( cos ] [ ] [ ] [ ] [ n n n n n n n n n R R R R + + = + + = + + = + = + =

Axis-angle Rotation Gien r Vector in space to rotate n Unit-length axis in space about which to rotate θ The amount about n to rotate Sole r The rotated ector n r r Week 9, Wed 29 Oct 03 Tamara Munzner 29

step 1 Axis-angle Rotation compute r par, an extended ersion of the rotation axis n r par = (n. r) n r par r r Week 9, Wed 29 Oct 03 Tamara Munzner 30

Axis-angle Rotation Compute r perp r perp = r r par = r - (n. r) n r perp r r Week 9, Wed 29 Oct 03 Tamara Munzner 31

Axis-angle Rotation Compute, a ector perpendicular to r par, r perp Use and r perp and θ to compute r cos(θ) r perp + sin(θ) θ r p Week 9, Wed 29 Oct 03 Tamara Munzner 32

Angular Displacement R(θ, n) is the rotation matrix to apply to a ector, then, R[]=cosθ + n(n.)(1-cosθ) + (nx) sinθ It guarantees a simple steady rotation between any two key orientations It defines moes that are independent of the choice of the coordinate system Week 9, Wed 29 Oct 03 Tamara Munzner 33

Axis-angle Notation solutions any orientation can be represented by a 4-tuple angle, ector(x,y,z) can interpolate the angle and axis separately no gimbal lock problems! problems no easy way to determine how to concatenate many axis-angle rotations that result in final desired axis-angle rotation so can t efficiently compose rotation, must conert to matrices first! Week 9, Wed 29 Oct 03 Tamara Munzner 34

Quaternions extend the concept of rotation in 3D to 4D aoids the problem of "gimbal-lock" and allows for the implementation of smooth and continuous rotation in effect, they may be considered to add a additional rotation angle to spherical coordinates ie. longitude, latitude and rotation angles a quaternion is defined using four floating point alues x y z w. These are calculated from the combination of the three coordinates of the rotation axis and the rotation angle. Week 9, Wed 29 Oct 03 Tamara Munzner 35

Quaternions Definition Extension of complex numbers 4-tuple of real numbers s,x,y,z or [s,] s is a scalar is a ector Same information as axis/angle but in a different form Can be iewed as an original orientation or a rotation to apply to an object Week 9, Wed 29 Oct 03 Tamara Munzner 36

Quaternion Extension of complex numbers: a + ib remember i 2 = -1 Quaternion: Q = a + bi + cj + dk Where i 2 = j 2 = k 2 = -1 and ij = k and ji = -k Represented as: q = (s, ) = s + x i + y j + z k Inented by Sir William Hamilton (1843) cared equation into Dublin bridge when discoered after decade of work Week 9, Wed 29 Oct 03 Tamara Munzner 37

Quaternion A quaternion is a 4-D unit ector q = [x y z w] It lies on the unit hypersphere x 2 + y 2 + z 2 + w 2 = 1 For rotation about (unit) axis by angle θ ector part = (sin θ/2) = [x y z] scalar part = (cos θ/2) = w (sin(θ/2) n x, sin(θ/2) n y, sin(θ/2) n z, cos (θ/2)) Only a unit quaternion encodes a rotation must normalize! Week 9, Wed 29 Oct 03 Tamara Munzner 38

Quaternion Rotation matrix corresponding to a quaternion: [x y z w] = 2 1 2y 2z 2xy 2wz 2xz+ 2wy Quaternion Multiplication q 1 * q 2 = [ 1, w 1 ] * [ 2, w 2 ] = [(w 1 2 +w 2 1 + ( 1 x 2 )), w 1 w 2-1. 2 ] quaternion * quaternion = quaternion this satisfies requirements for mathematical group Rotating object twice according to two different quaternions is equialent to one rotation according to product of two quaternions 2 2xy+ 2wz 2 1 2x 2z 2yz 2wx 2 2xz 2wy 2yz+ 2wx 2 1 2x 2y Week 9, Wed 29 Oct 03 Tamara Munzner 39 2

Quaternion Example (sin(θ/2) n x, sin(θ/2) n y, sin(θ/2) n z,, cos (θ/2)) X-roll of π radians [90 º] (sin (π/2) (1, 0, 0), cos (π/2)) = ( (1, 0, 0), 0 ) Y-roll 0f π ( (0, 1, 0), 0) Z-roll of π ( (0, 0, 1), 0) R y (π) followed by R z (π) ( (0, 1, 0), 0) times ( (0, 0, 1), 0 ) = Week 9, Wed 29 Oct 03 Tamara Munzner 40

Quaternion Interpolation biggest adantage of quaternions cannot linearly interpolate (lerp) between two quaternions because it would speed up in middle instead, spherical linear interpolation, (slerp) ensure ectors remain on the hypersphere step through using constant angles Week 9, Wed 29 Oct 03 Tamara Munzner 41

SLERP Quaternion is a point on the 4-D unit sphere interpolating rotations requires a unit quaternion at each step another point on the 4-D unit sphere moe with constant angular elocity along the great circle between two points Any rotation is defined by 2 quaternions, so pick the shortest SLERP To interpolate more than two points, sole a nonlinear ariational constrained optimization Ken Shoemake in SIGGRAPH 85 (www.acm.org/dl) Week 9, Wed 29 Oct 03 Tamara Munzner 42

Quaternion Libraries Gamasutra Code, explanatory article Registration required http://www.gamasutra.com/features/19980703/quaternions_01.htm Week 9, Wed 29 Oct 03 Tamara Munzner 43

Adantages: Ealuating Quaternions Flexible. No parametrization singularities (gimbal lock) Smooth consistent interpolation of orientations. Simple and efficient composition of rotations. Disadantages: Each orientation is represented by two quaternions. Complex! Week 9, Wed 29 Oct 03 Tamara Munzner 44

3x3 matrices Summary drifting, can t interpolate Euler angles gimbal lock axis-angle can t concatenate or interpolate quaternions sole all problems, but complex Week 9, Wed 29 Oct 03 Tamara Munzner 45

Project Strategy Suggestion debug basics with simple euler angles with single drag, does iew change the right way? then can add quaternions Week 9, Wed 29 Oct 03 Tamara Munzner 46