MATH 245 Extra Effort ( points) My assistant read through my first draft, got half a page in, and skipped to the end. So I will save you the flipping. Here is the assignment. Do just one of them. All the rest is just my idea about putting some information together. For the extra credit, choose one of the following.. Prove Formula an and all of the Claims in the text below. Show all work. 2. Find a C++ library (or class) for quaternion multiplication or write a simple one of your own. Use it to π rotate the unit sphere about the axis 2,,2 by. In particular, find the image of points (,,), 3 (,,), and (,,) under the rotation. Turn in the source code, the rotation quaternion, and the images. 3. Use the quaternion multiplication package in Mathematica to perform the same rotation described in 2. Turn in the Mathematica notebook. It should include the rotation quaternion used, the images of the three points, and a graph of the unit sphere showing (,,), the axis of rotation, and the image of (,,) under the rotation. A Little Algebra At some point in your early mathematical history you learned how to multiply and divide real numbers. The real numbers correspond to the real line or R. There is a multiplicative identity, namely, since a =a for every real number. Every non-zero number has a multiplicative inverse, namely its reciprocal: a a= a a =a a = Division turned out to be equivalent to multiplication: a b= a b =a b. Later on, you learned the arithmetic of complex numbers, including division. What you may not have thought about was that you can think of any complex number as an ordered pair: a + bi corresponds to (a,b). Thus, complex arithmetic can be thought of as arithmetic on ordered pairs; ie, the real plane, R 2 via the operations (a,b)+ (c,d)=(a+ c,b+ d ) (a,b) (c,d )=(a c,b d) (a,b) (c, d )=(ac bd, ad + bc) (a,b) (,)=(a, b) (a,b) =, b) =(a (a,b) (a,b) where (a, b) = + The last expression is sometimes called the modulus of (a,b) and (a,-b) is the conjugate of (a,b), sometimes denoted as (a,b). In R 3, we have learned to associate points with position vectors and can add and subtract in a sensible way; ie, component-wise, a natural extension of the case in R 2. Now we come to a problem. There does not seem to be a natural way to extend multiplication via vectors. We have two vector products, the dot and cross products, which while very useful, do not extend to division; there is no multiplicative identity and so no multiplicative identity, hence no equivalence with division. Question : Is it possible to sensibly multiply and divide ordered triples? A Little Geometry Let's turn to the geometry and transformations of real spaces, especially objects in those spaces (lines, points, angles). For now, we will restrict our attention to rigid transformations, those that preserve length and angles. This omits a lot of transformations, including scaling and shearing. In R, the only rigid transformations are translation, x x+ a, and reflection about the origin, x x.
In R 2, we have both of these and we pick up rotation as well. For translation, we have (x, y) ( x+ a, y+ b). For reflection, we are no longer restricted to the origin, but have two axes we can reflect in: (x, y) ( x, y) reflects in the y-axis and (x, y) ( x, y) reflects in the x-axis. (With the help of rotation, we will be able to reflect in an arbitrary line through the origin.) To represent rotations, we are going to use matrix multiplication. Let θ be any angle and [ x be the column matrix that represents an y] arbitrary point (x,y). Then [ ] [ x y] = [ x' y '] gives the rotation in matrix form where (x', y') is the image of (x,y) under the rotation. This transformation has an inverse, namely rotation by θ. To reflect in an arbitrary line through the origin, rotate it to line up with the x-axis, perform the reflection, then rotate back. It is worth noting that x-axis reflection also has a matrix representation [ ] [ x y] [ = x y] so that the reflection can be represented as a string of matrix multiplications. It is worth noting at this point that these reflections and rotations are linear transformations, a field of intense study and application (consider putting Linear Algebra on your course list). In fact, they are the only rigid linear transformations of R 2. (If you would like to see how to program 2D transformations in Excel, click here.) Reflection in the x-axis can be represented in the complex plane as conjugation: z z. Rotation in the plane can also be expressed in complex form: r e i θ r e i (θ+ α ) where α is the angle of rotation. (Nice, isn't it?) In R 3 the situation becomes a bit more complex. For the most part, things extend nicely from R 2. Since translations are not linear transformations, we omit them here. However, we have reflection in three coordinate planes: (x, y, z) ( x, y, z), (x, y, z) (x, y, z), and (x, y, z) (x, y, z) reflect in yz-, xz-, and xy-planes, respectively. We also have rotation about 3 coordinate axes which, as in the case of R 2, have matrix representations: R x= [ ], R y= [ cos θ ], R z= [ ] Rotation about an arbitrary axis through the origin can be decomposed into three basic rotations and hence, three matrix multiplications. The angles associated with each rotation are called the Euler angles. This seems very straightforward at first but suffers from a few drawbacks: computational inefficiency, non-uniqueness of the decomposition, and in computer graphics the transition through multiple rotations may not be smooth. Question 2: Is there hope for a simple way to obtain rotations in R 3 that avoids some or all of these difficulties? Gimbal Lock? I personally became acquainted with gimbal lock while researching this assignment so I will not pretend to know much about it. It occurs in 3D computer graphics, robotics, aeronautical guidance systems, in fact, anywhere that Euler angles have been used to describe/govern 3D rotation. It is essentially the loss of a degree of freedom in the rotation. The wiki on this topic has nice pictures to understand the physical problem as it pertains to gyroscopes. Question 3: Is there a computational method to avoid gimbal lock?
Quaternions The solution to these seemingly disparate problems has its roots in Question. William Hamilton is first credited with solving the problem and coined his discovery quaternions. Apparently Gauss knew about quaternions but did not publish his discoveries. (By the way, Carl Friedrich Gauss knew everything.) Hamilton devoted much of his life teaching and disseminating quaternion mathematics which was largely abandoned with the introduction of vector analysis. Here is a very brief introduction to quaternions. It is necessary to supply a definition and then define the operations, in particular, multiplication. Both division and rotation in R 3 using quaternions requires an understanding of multiplication and its properties, so we go into some detail. Let a,b,c, and d be real numbers and i 2 = j 2 =k 2 =ijk=. It follows that i j=k, j k=i, and k i= j. Since ji= j( jk )= jjk= j 2 k= k, we also have ji= k, k j= i and i k= j. Now define a quaternion, q, as q=a+ bi+ cj+ dk We can immediately define the norm of q as q = + + +. You may have been expecting modulus or magnitude here, but norms are used to create metrics; ie, a way to measure distances and lengths. One requirement for rotation to be considered a rigid motion is that it must preserve lengths and distances between points, as well as angles. As with complex numbers, we add and subtract in the usual way. For multiplication, let q =a i+ c j+ d k and q 2 = + i+ j+ k use the distributive property. We obtain an algebraic form (or Hamilton form) for a product of two quaternions, Formula : q q 2 =(a b c d ) + (a + c d )i + (a b + c + d ) j + (a c + d )k We can also associate a quaternion with a scalar and a vector via a+ bi+ cj+ dk a+ b,c, d =a+ v. Letting q =a + v and q 2 = + v 2, we can derive a vector form of quaternion multiplication Formul: q q 2 = a v v 2 a v 2 v v v 2 using the usual dot and cross products. This form has immediate use in developing some properties of quaternion arithmetic. Additionally, we have a matrix representation for quaternions and for multiplication. [ a b c d ] a+ bi+ cj+ dk b a d c c d a b d c b a Claim : To multiply two quaternions, multiply their matrix representations. We now seek a quaternion, call it e, with the property that qe=q for any quaternion, q. I found this to be relatively easy by writing q=a+ v and e=b+ u then using the vector form of multiplication and properties of vectors to obtain Claim 2: e=+ In matrix form, e is the identity matrix of dimension 4. A multiplicative inverse for q, call it q, must
satisfy either q q =e or q q=e. It turns out that Claim 3: q = q* q 2 satisfies both equations where q * is the conjugate of q and can be written in at least two useful ways. Letting q=a+ v, q * =q+ iqi+ jqj+ kqk or q * =a v The first has the advantage that the scalar and vector parts of q can be written as 2 (q+ q* ) and 2 (q q* ), respectively. The second looks like a conjugate. It is easy to show that q q * = q 2, just as with complex numbers. We are ready to define division and must set a convention. There is not a universal rule for, but any work with quaternions must establish what is meant by p q. Since quaternion multiplication does not generally commute, one is obliged to choose either q p or p q. This answers Question. We are ready to perform rotation in R 3 using unit quaternions. A unit quaternion satisfies q 2 = and q =q *. Let u be a unit vector in R 3 that is collinear with the desired axis of rotation and let θ be the amount of rotation. Let q=cos ( θ quaternion 2) + usin ( θ 2). Associate a point P in R 3, say ( x, y,z ) with the P=+ x, y, z. The image of P under the rotation is P' where Formula 3: P ' =qpq =qpq * This is our definition then of rotation in R 3 via quaternion multiplication and answers Question 2. It remains to be shown that this is norm and angle preserving. These are non-trivial tasks. What better way to spend your free time! As for Question 3, I lack the knowledge to illustrate the application of quaternions to any specific field and mention it here because I knew someone would ask what are they good for? If you come across especially good resources for understanding gimbal lock, rotation in 3D, or other interesting applications other than those listed below, I will consider adding a couple of points. Just quote the source and write a paragraph about why you would recommend it to someone else. Sources. Mathematics for 3D Game Programming, Eric Lengyel, 22, ISBN 5845379 2. http://en.wikipedia.org/wiki/quaternion 3. http://en.wikipedia.org/wiki/gimbal_lock 4. http://en.wikipedia.org/wiki/euler_angles