Download presentation
Presentation is loading. Please wait.
Published byWinfred Barber Modified over 9 years ago
1
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE
2
INTRODUCTION Quaternions invented by Sir William Rowan Hamilton in 1843 Developed as extension to complex numbers Introduced into computer graphics by Ken Shoemake in 1985 Very good for rotation transformations better than Euler angles because: Straightforward to convert to and from quaternions Stable and constant interpolation of orientations http://commons.wikimedia.org/wiki/Fi le%3AWilliam_Rowan_Hamilton_portr ait_oval_combined.png
3
COMPLEX NUMBERS Complex number = 2 part real + imaginary part A + iB Imaginary number i = sqrt(-1)
4
SO WHAT IS A QUATERNION? Quaternion = has 4 parts First 3 parts imaginary vector (each component uses a different imaginary number) Last part real part of quaternion In practice, stored as a 4D vector of real numbers (but usually put little hat on name)
5
NOTES ABOUT QUATERNIONS Imaginary part q v can be treated like an ordinary vector So we can do vector addition, dot product, cross product, etc. Multiplying the imaginary units (i,j,k) is NONCOMMUTATIVE ORDER MATTERS! Note: looks like what happens when you use the cross product (e.g., (y axis) x (z axis) = (x axis))
6
MULTIPLYING QUATERNIONS Remember: parts of each quaternion are added together, BUT can’t actually add them because of the imaginary terms Recall:
7
RULES OF QUATERNIONS Addition: Just add imaginary and real parts separately Conjugate: Negate imaginary parts; leave real part alone Norm: Imaginary parts cancel out, leaving only the real parts Identity: Conjugate for regular imaginary numbers:
8
INVERSE OF QUATERNIONS The inverse must have the following property: We know the following to be true from the definition of the norm: Thus, the inverse is given by: Norm:
9
SCALAR MULTIPLICATION To multiply a scalar s by a quaternion: Also, it is commutative:
10
UNIT QUATERNION Unit quaternion Another way to write this is: This works because: …only works if:
11
EULER’S FORMULA Turns out that sine, cosine, i, and e are all related by Euler’s Formula: The equivalent for quaternions is: We’ll use this later… Aside: when φ = π, get Euler’s Identity!
12
QUATERNION TRANSFORMS Unit quaternion can represent ANY 3D rotation! Rotates points around axis u q by an angle 2φ Advantages: Extremely compact and simple A lot easier to interpolate between orientations Converting to/from quaternions straightforward
13
USING QUATERNION TRANSFORMS Assume we have a point we want to transform as a 4D homogeneous vector p Put p into a quaternion The following rotates p around axis u q by an angle 2φ: Moreover, since we’re dealing with unit quaternions: So, the final transformed point is given by:
14
MULTIPLE ROTATIONS One important rule of the quaternion conjugate: So, to apply two rotations, q and then r:
15
CONVERT TO A MATRIX The following gives you the corresponding rotation matrix: Where: Once you have the quaternion, no trigonometric functions need to be computed!
16
CONVERT FROM A MATRIX If q w is not very small: Otherwise, have to find largest component using: Compute largest using: Compute the rest:
17
SPHERICAL LINEAR INTERPOLATION Spherical Linear Interpolation = given two unit quaternions, q and r, and a parameter t ([0,1]), computes an interpolated quaternion Useful for animation Less useful for camera orientations can tilt camera’s “up” vector Mathematically expressed as: Power law for quaternions:
18
SLERP() Software implementation, slerp(), often uses this form: To get φ: There are, however, faster incremental approaches that avoid the trigonometric functions
19
INTERPOLATED QUATERNIONS Interpolation path is unique PROVIDED q and r are not exact opposites Shortest arc on 4D unit sphere Constant speed, zero acceleration geodesic curve NOTE: Interpolation q 1 q 3 is NOT the same path as q 1 q 2 q 3 (even though the destination is the same) Also note: not smooth transition from q 1 q 2 to q 2 q 3 Better to use a spline-based interpolation with quaternions (e.g., squad())
20
TRANSFORMING FROM ONE VECTOR TO ANOTHER You can also directly transform from one direction s to another direction t using the shortest path possible Normalize s and t Compute normalized rotation axis using cross product: Compute dot product: Get length of cross product: Quaternion we want: Using half-angle relations and some simplifications:
21
TRANSFORMING FROM ONE VECTOR TO ANOTHER The matrix for this kind of rotation can be efficiently computed without trigonometric functions:
22
TRANSFORMING FROM ONE VECTOR TO ANOTHER NOTE: Need to detect when s and t point in: Exactly same direction return identity matrix/quaternion Exactly opposite directions pick any axis of rotation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.