Rotations and Quaternions Week 9, Wed 29 Oct 2003

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

CS B659: Principles of Intelligent Robot Motion Rigid Transformations.
Animation Following “Advanced Animation and Rendering Techniques” (chapter 15+16) By Agata Przybyszewska.
Chris Hall Aerospace and Ocean Engineering
Orientation & Quaternions
Computer Graphics Recitation 2. 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions.
3D Coordinate Systems and Transformations Revision 1
3D orientation.
CSCE 689: Computer Animation Rotation Representation and Interpolation
CSCE 441: Computer Graphics Rotation Representation and Interpolation
CSCE 641: Computer Graphics Rotation Representation and Interpolation Jinxiang Chai.
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
CS 445 / 645 Introduction to Computer Graphics Lecture 21 Representing Rotations Lecture 21 Representing Rotations.
CS I400/B659: Intelligent Robotics Rigid Transformations.
CS 450: COMPUTER GRAPHICS 3D TRANSFORMATIONS SPRING 2015 DR. MICHAEL J. REALE.
Computer Vision Group Prof. Daniel Cremers Autonomous Navigation for Flying Robots Lecture 3.1: 3D Geometry Jürgen Sturm Technische Universität München.
1 Kinematics ( 運動學 ) Primer Jyun-Ming Chen Fall 2009.
Game Physics – Part IV Moving to 3D
3D Kinematics Consists of two parts 3D rotation 3D translation  The same as 2D 3D rotation is more complicated than 2D rotation (restricted to z- axis)
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE.
Computer Graphics Bing-Yu Chen National Taiwan University.
3D Computer Graphics An oh so brief introduction.
Rotations and Translations
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
1 CS 430/536 Computer Graphics I 3D Transformations World Window to Viewport Transformation Week 2, Lecture 4 David Breen, William Regli and Maxim Peysakhov.
Advanced Computer Graphics Spring 2014
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Rotations and Quaternions Week 9, Wed 29 Oct 2003.
Rotation and Orientation: Fundamentals Jehee Lee Seoul National University.
CS 551/645 Fall 2000 Parameterized Rotations, Curves, and Surfaces.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 17, 2015 TRANSFORMATIONS AFFINE TRANSFORMATIONS QUATERNIONS.
CS 551/651 Advanced Graphics Technical Background.
Euler Angles This means, that we can represent an orientation with 3 numbers Assuming we limit ourselves to 3 rotations without successive rotations about.
Computer Graphics I, Fall 2010 Transformations.
Week 5 - Monday.  What did we talk about last time?  Lines and planes  Trigonometry  Transforms  Affine transforms  Rotation  Scaling  Shearing.
Introduction to Computer Graphics CS 445 / 645 Lecture 10 Chapter 7: Transformations Gimbal.
Fundamentals of Computer Animation Orientation and Rotation.
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
Transformations Review 4/18/2018 ©Babu 2009.
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
CPSC 641: Computer Graphics Rotation Representation and Interpolation
CS 445 / 645 Introduction to Computer Graphics
Transformations Objectives
3D Kinematics Consists of two parts
Computer Graphics CC416 Week 15 3D Graphics.
Transformations contd.
More Rigid Transforms, 3D Rotations
COMPUTER GRAPHICS CHAPTERS CS 482 – Fall 2017 TRANSFORMATIONS
Computer Graphics Viewing
3D Transformations Source & Courtesy: University of Wisconsin,
Review: Transformations
Rotation representation and Interpolation
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Rotation Representations
Lecture 13 Clipping & Scan Conversion
(c) University of Wisconsin, CS559
UMBC Graphics for Games
CS-378: Game Technology Lecture #2: Transformations Prof. Okan Arikan
Transformations Ed Angel
Geometric Objects and Transformations (II)
Interactive Computer Graphics Transformations
Transformations Ed Angel Professor Emeritus of Computer Science
VIRTUAL ENVIRONMENT.
Isaac Gang University of Mary Hardin-Baylor
UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN
Game Programming Algorithms and Techniques
Clipping University of British Columbia CPSC 314 Computer Graphics
Rotation and Orientation: Fundamentals
Presentation transcript:

Rotations and Quaternions Week 9, Wed 29 Oct 2003

Clipping recap

Clipping analytically calculating the portions of primitives within the viewport Week 9, Wed 29 Oct 03 © Tamara Munzner

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

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

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

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

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

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

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

Rotations and Quaternions

Camera Movement Hints change viewing transformation methods don’t try doing this with perspective 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

Parameterizing Rotations Straightforward in 2D A scalar, q, 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 have 6 degrees of freedom (DOF) Week 9, Wed 29 Oct 03 © Tamara Munzner

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

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 very bad Numerical errors results when trying to gradually rotate matrix by adding derivatives 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

Rotation Matrix general rotation can be represented by a single 3x3 matrix length preserving (isometric) reflection preserving orthonormal problem: property: rows and columns are orthonormal (unit length and perpendicular to each other) linear interpolation doesn’t maintain this property So direct Interpolation of Transformation Matrix is not acceptable Week 9, Wed 29 Oct 03 © Tamara Munzner

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

Euler Angles (qx, qy, qz) = RzRyRx Axis order is not defined Rotate qx degrees about x-axis Rotate qy degrees about y-axis Rotate qz 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

Euler Angle Interpolation solution 1: can interpolate angles individually problem 2: interpolation between two Euler angles is not unique ex: (x, y, z) rotation (0, 0, 0) to (180, 0, 0) vs. (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

Interpolation Week 9, Wed 29 Oct 03 © Tamara Munzner

Interpolation Week 9, Wed 29 Oct 03 © Tamara Munzner

Euler Angles Problem 3: Gimbal Lock term derived 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

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

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

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

Axis-angle Rotation n=(nx, ny, nz) A counter-clockwise (right-handed) q y A counter-clockwise (right-handed) rotation q about the axis specified by the unit vector n=(nx, ny, nz) x Week 9, Wed 29 Oct 03 © Tamara Munzner

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

Angular displacement (,n) defines an angular displacement of  about an axis n Week 9, Wed 29 Oct 03 © Tamara Munzner

Axis-angle Rotation Given r – Vector in space to rotate n – Unit-length axis in space about which to rotate q – The amount about n to rotate Solve r’ – The rotated vector r’ r n Week 9, Wed 29 Oct 03 © Tamara Munzner

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

Axis-angle Rotation Compute rperp rperp = r – rpar = r - (n . r) n Week 9, Wed 29 Oct 03 © Tamara Munzner

Axis-angle Rotation Compute v, a vector perpendicular to rpar , rperp Use v and rperp and q to compute r’ v q cos(q) rperp + sin(q) v rp Week 9, Wed 29 Oct 03 © Tamara Munzner

Angular Displacement R(q, n) is the rotation matrix to apply to a vector v , then, R[v]=vcosq + n(n.v)(1-cosq) + (nxv) sinq It guarantees a simple steady rotation between any two key orientations It defines moves that are independent of the choice of the coordinate system Week 9, Wed 29 Oct 03 © Tamara Munzner

Axis-angle Notation solutions problem any orientation can be represented by a 4-tuple angle, vector(x,y,z) can interpolate the angle and axis separately no gimbal lock problems! problem 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 convert to matrices first! Week 9, Wed 29 Oct 03 © Tamara Munzner

Quaternions extend the concept of rotation in 3D to 4D avoids 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 values |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

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

Quaternion Extension of complex numbers: a + ib Quaternion: remember i2 = -1 Quaternion: Q = a + bi + cj + dk Where i2 = j2 = k2 = -1 and ij = k and ji = -k Represented as: q = (s, v) = s + vxi + vyj + vzk Invented by Sir William Hamilton (1843) carved equation into Dublin bridge when discovered after decade of work Week 9, Wed 29 Oct 03 © Tamara Munzner

Quaternion A quaternion is a 4-D unit vector q = [x y z w] It lies on the unit hypersphere x2 + y2 + z2 + w2 = 1 For rotation about (unit) axis v by angle q vector part = (sin q/2) v = [x y z] scalar part = (cos q/2) = w (sin(q/2) nx, sin(q/2) ny, sin(q/2) nz, cos (q/2)) Only a unit quaternion encodes a rotation must normalize! Week 9, Wed 29 Oct 03 © Tamara Munzner

Quaternion Rotation matrix corresponding to a quaternion: [x y z w] = Quaternion Multiplication q1 * q2 = [v1, w1] * [v2, w2] = [(w1v2+w2v1+ (v1 x v2)), w1w2-v1.v2] quaternion * quaternion = quaternion this satisfies requirements for mathematical group Rotating object twice according to two different quaternions is equivalent to one rotation according to product of two quaternions Week 9, Wed 29 Oct 03 © Tamara Munzner

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

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 move with constant angular velocity 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, solve a non-linear variational constrained optimization Ken Shoemake in SIGGRAPH ’85 (www.acm.org/dl) Week 9, Wed 29 Oct 03 © Tamara Munzner

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

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

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

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