Quaternions are back!!! A global quaternion q is defined as q = q0 + q where q = q1I+ q2 J+ q3K . where q0 is a scalar and q is a vector. A quaternion.

Slides:



Advertisements
Similar presentations
5.1 Real Vector Spaces.
Advertisements

Chapter 4 Euclidean Vector Spaces
John C. Hart CS 318 Interactive Computer Graphics
12 VECTORS AND THE GEOMETRY OF SPACE.
Mathematics. Matrices and Determinants-1 Session.
Chapter 7: Vectors and the Geometry of Space
6 6.1 © 2012 Pearson Education, Inc. Orthogonality and Least Squares INNER PRODUCT, LENGTH, AND ORTHOGONALITY.
Computer Graphics Recitation 2. 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions.
Ch. 2: Rigid Body Motions and Homogeneous Transforms
Ch 7.3: Systems of Linear Equations, Linear Independence, Eigenvalues
ME451 Kinematics and Dynamics of Machine Systems Review of Matrix Algebra – 2.2 Review of Elements of Calculus – 2.5 Vel. and Acc. of a point fixed in.
APPLICATIONS OF TRIGONOMETRY
2IV60 Computer Graphics Basic Math for CG
Engineering Mechanics: Statics
Rotations and Translations
Compiled By Raj G. Tiwari
1 February 24 Matrices 3.2 Matrices; Row reduction Standard form of a set of linear equations: Chapter 3 Linear Algebra Matrix of coefficients: Augmented.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE.
Review of Matrices Or A Fast Introduction.
Rotations and Translations
4 4.4 © 2012 Pearson Education, Inc. Vector Spaces COORDINATE SYSTEMS.
Vectors CHAPTER 7. Ch7_2 Contents  7.1 Vectors in 2-Space 7.1 Vectors in 2-Space  7.2 Vectors in 3-Space 7.2 Vectors in 3-Space  7.3 Dot Product 7.3.
Matrices CHAPTER 8.1 ~ 8.8. Ch _2 Contents  8.1 Matrix Algebra 8.1 Matrix Algebra  8.2 Systems of Linear Algebra Equations 8.2 Systems of Linear.
Sect. 4.2: Orthogonal Transformations
Animating Rotations and Using Quaternions. What We’ll Talk About Animating Translation Animating 2D Rotation Euler Angle representation 3D Angle problems.
Copyright © Cengage Learning. All rights reserved. 12 Vectors and the Geometry of Space.
Vectors and the Geometry
VECTORS AND THE GEOMETRY OF SPACE. The Cross Product In this section, we will learn about: Cross products of vectors and their applications. VECTORS AND.
Linear Algebra Chapter 2 Matrices.
Basic Theory (for curve 01). 1.1 Points and Vectors  Real life methods for constructing curves and surfaces often start with points and vectors, which.
Computer Graphics Mathematical Fundamentals Lecture 10 Taqdees A. Siddiqi
Learning from the Past, Looking to the Future James R. (Jim) Beaty, PhD - NASA Langley Research Center Vehicle Analysis Branch, Systems Analysis & Concepts.
Learning from the Past, Looking to the Future James R. (Jim) Beaty, PhD - NASA Langley Research Center Vehicle Analysis Branch, Systems Analysis & Concepts.
Quantum Two 1. 2 Angular Momentum and Rotations 3.
Vectors and the Geometry
MAT 322: LINEAR ALGEBRA.
3 DERIVATIVES.
CPT450 – Computer Graphics
Matrix Algebra MATRIX OPERATIONS © 2012 Pearson Education, Inc.
10.4 The Algebra of Matrices
Geometric Transformations
7.7 Determinants. Cramer’s Rule
Ch. 2: Rigid Body Motions and Homogeneous Transforms
Problem 1.5: For this problem, we need to figure out the length of the blue segment shown in the figure. This can be solved easily using similar triangles.
Vectors Lesson 2 recap Aims:
Matrix Algebra MATRIX OPERATIONS © 2012 Pearson Education, Inc.
Linear Algebra Linear Transformations. 2 Real Valued Functions Formula Example Description Function from R to R Function from to R Function from to R.
ROTATIONS & TRANSLATIONS
Systems of First Order Linear Equations
Lecture 03: Linear Algebra
Basic Math Review (you already know this stuff ...)
Degree and Eigenvector Centrality
Introduction to Vectors and Frames
Making a Point: Elementary (around Z?) Rotations in 2D …
Making a Point: Elementary (around Z?) Rotations in 2D …
Lesson 81: The Cross Product of Vectors
Vectors and the Geometry of Space
Vectors and the Geometry
Rotational Kinematics
3D Transformation CS380: Computer Graphics Sung-Eui Yoon (윤성의)
2.1 Day 3 Linear Transformations
A definition we will encounter: Groups
EIGENVECTORS AND EIGENVALUES
Chapter 2. Geometrical Methods
Matrix Algebra MATRIX OPERATIONS © 2012 Pearson Education, Inc.
General Vector Spaces I
Matrix Algebra THE INVERSE OF A MATRIX © 2012 Pearson Education, Inc.
Vector Spaces COORDINATE SYSTEMS © 2012 Pearson Education, Inc.
Presentation transcript:

Quaternions are back!!! A global quaternion q is defined as q = q0 + q where q = q1I+ q2 J+ q3K . where q0 is a scalar and q is a vector. A quaternion can also be shown in its flag form: q = q0 + q1i+ q2 j + q3k . where i, j and k are the flags (unit vectors) defined as follows: i2 = j2 = k2 = ijk = -1; ij = -ji = k; jk = - kj = i; ki = -ik = j. Addition of two quaternions is a quaternion (closure under addition) q + p = (q0 + q1i+ q2 j + q3k) + (p0 + p1i+ p2 j + p3k) = (q0 + p0) + (q1 + p1) i + (q2 + p2) j + (q3 + p3) k Quaternion addition is commutative, q + p = p + q, and associative (q + p) + r = q + (p + r) (easy to prove).

Product of quaternions and other properties ... The product of two quaternions is a quaternion defined as follows: qp = (q0 + q)(p0 + p) = q0p0 + q0p + p0q + qp, where: qp = q x p – q . p Here qp is the cross product minus the dot product of vectors q and p (in that order, q goes first). In the product of two quaternions the scalar part is “q0p0 – q . p“, and the rest is a vector part. qp = q0p0 – q.p + q0p + p0q + q x p Quaternion multiplication is not commutative, however it is associative, and distributes over addition. That is, for three quaternions p, q and r: (pq)r = p(qr) and (p + q)r = pr + qr

Product of quaternions: Exercise # 28 Exercise: Given p = 3 + i – 2j + k and q = 2 – i +2j +3k, calculate their product. Answer: The product is given by pq = q0p0 – p.q + q0p + p0q + p x q = 8 - 9i - 2j + 11k First find the dot product: p.q = (1)*(-1) + (-2)*(2) + (1)*(3) = (-1) + (-4) + (3) = -2. Next the cross product: p x q = [ i j k] [1 -2 1] = (-6 – 2)i - (3 – (-1))j + (2 – 2)k = -8i -4j [-1 2 3] Etc … REMEMBER: WHATEVER YOU DO WITH A QUATERNION PRODUCT YOU MUST END UP WITH A SCALAR FOLLOWED BY A VECTOR (any of them can be a 0)!

Product of quaternions and other properties ... A quaternion q = q0 + q has a conjugate q* = q0 – q (similar to complex numbers). If q = q0 + q1I + q2 J + q3K then q* = q0 - q1I - q2 J - q3K . Hence: q + q* = 2q0 and qq* = q*q = |q|2 = (q0)2 + (q1)2 + (q2)2 + (q3)2 (verify this!) A quaternion has an inverse q-1 = 1/q = q*/|q|2 A unit quaternion is such that |q| = 1 and for this unit quaternion q-1 = q*. The unit quaternion is: q = 1 + 0, that is, the unit quaternion has the scalar part of 1 (hence: (q0)2 + (q1)2 + (q2)2 + (q3)2 = 1) and the vector part of 0. The zero and the negative (additive inverse) quaternions are trivially defined as “0” and “-q”.

Evaluating a Unit quaternion:Exercise # 29 A unit quaternion is one such that |q| = 1 and for the unit quaternion q-1 = q* qq* = q*q = |q| = (q0)2 + (q1)2 + (q2)2 + (q3)2 = 1 Example: Given the quaternion q = q0 + q = 1.1 + 2.5 i – 4.5 j + 1.6 k, calculate the corresponding unit quaternion p. Solution: |q| = (q0)2 + (q1)2 + (q2)2 + (q3)2 = sqrt(1.21 + 6.25 + 20.25 + 2.56) = sqrt(30.27) = 5.5018 p = q/|q| = 0.2 + 0.4544 i – 0.8179 j + 0.2908 k. Thus, |p| = 0.04+0.2065+0.6690+0.0846 = 1.0001 = 1.00005 (it’s 1 with round off errors) Also p* = 0.2 - 0.4544 i + 0.8179 j - 0.2908 k. It’s easy to verify that pp* = p*p = 1.

Quaternions as 4 x 4 matrices As we know, the product of two quaternions can be expressed using algebra of matrices. For this let: p = p0 + p = p0 + p1i+ p2 j+ p3k, and q = q0 + q = q0 + q1i+ q2 j+ q3k, and let’s designate the product as the quaternion r such that: r = pq = r0 + r = r0 + r1i+ r2 j+ r3k We can verify that the product pq can be written in matrix notation as follows: p0 -p1 -p2 -p3 p1 p0 -p3 p2 p2 p3 p0 -p1 p3 -p2 p1 p0 r0 r1 r2 r3 q0 q1 q2 q3 r = = = Pq It’s easy to verify that matrix quaternion Q has the property of a rotation matrix, that is: Q-1 = Qt. Also, matrix Q can be represented as follows: Q = , where p’ = , compare p’ with vector v used in the Rodrigues formula (Ch 3a, # 2). 0 -p3 p2 p3 0 -p1 -p2 p1 0 p0 - pt p p0 I3 + p’

Product of quaternions: Exercise # 30 Example: Given p = 3 + i – 2j + k and q = 2 – i +2j +3k, calculate their product using the quaternion matrix representation. Answer: Let r = pq, then: p0 -p1 -p2 -p3 p1 p0 -p3 p2 p2 p3 p0 -p1 p3 -p2 p1 p0 = r0 r1 r2 r3 q0 q1 q2 q3 3 -1 2 -1 1 3 -1 -2 -2 1 3 -1 1 2 1 3 2 -1 3 = Pq = 6 + 1 + 4 - 3 2 - 3 - 2 - 6 - 4 - 1 + 6 - 3 2 - 2 + 2 + 9 8 -9 -2 11 Therefore, r = pq = 8 – 9 i – 2 j + 11 k. As given, P must have an inverse and a transpose. Verify if Pt = P-1 (and be surprised!), otherwise calculate the formula for P-1 using the formula given in the previous slide. Also, find det(P) = 225 ≠ 1? Etc ..

Quaternion and vectors A vector can be treated as a quaternion whose “scalar” (or “real” part) is 0: thus v  R3 is now q  R4 . This quaternion q with real part 0, is called a pure quaternion”. (The set Q0 of pure quaternions is a subset of the set Q of all quaternions). Multiplication of a quaternion and a vector is not a vector: qv = (q0 + q)(0 + v) = - q . v + q0v + q x v  Q (not in Q0). Verify it! Two triple products generating a vector (pure quaternion): Whenever v is a vector (pure quaternion), and q is a quaternion, the products: qvq* and q*vq are pure quaternions (vectors). Most important results!!! Verify it! Typically we write Lq(v) = qvq* to indicate that qvq* is an operator (in fact a linear operator) Associating an angle to a unit quaternion: Let q = q0 + q be a unit or “normalized” quaternion, that is (q0)2 + |q|2 = 1. For any angle q we can associate (q0)2 = cos2 q and |q|2 = sin2 q and q is unique when -p < q  p. Let now be u the unit vector that represents the direction of q. We write u = q/|q| = q/sin q. Hence q = q0 + q = cos q + u sin q. And we can easily verify that (important result!): q* = q0 - q = cos q - u sin q = cos (-q) + u sin (-q).

The Operator Lq(v) = qvq* is linear Linear operator “Lq(v) = qvq*” satisfies the following property: For any two vectors a and b in R3 and for any scalar (real number) k, Lq is a linear operator if it satisfies: Lq(ka + b) = kLq(a) + Lq(b) Proof: (we use the property of quaternions being associative & distributive - slide #2 in this set of notes) Lq(ka + b) = q(ka + b)q* = (kqa + qb)q* = kqaq* + qbq* = kLq(a) + Lq(b) Therefore, the operator Lq(v) = qvq* is a linear operator (a most important property)

Quaternions and vectors: Exercise # 31 Exercise: Given the vector v = (3, -1, 2.5) and the quaternion q = q0 + q = -7 – 2i + 5j + 3k. Find the products qv, vq, qvq* and q*vq, verifying that qv and vq are quaternions while qvq* and q*vq are pure quaternions (vectors). Make quaternion r = vq a unit quaternion and find the angle q associated with r. Solution: qv = Etc...

Quaternion with Angle q = p/6 and vector k: Exercise # 32 Example: In this case q = p/6 and the unit quaternion is: q = cos q + k sin q = 3/2 + (1/2)k Assume that the basis vector is: v = 1i + 0j + 0k and let’s compute Lq(v) = w = qvq* = (3/2 + (1/2)k)(0+i) (3/2 - (1/2)k), that is: w = qvq* = (1/2)i + (3/2)j = cos(p/3)i + sin(p/3)j. We notice that the angle associate with w is 2*p/6 = p/3 and that w is a unit vector. Generalization: Assume that the angle is simply q with vector k. Then q = cos q + k sin q, while v = i and w = qvq*. Therefore: w = qvq* = (cos q + k sin q )(0 + i) (cos q - k sin q ) = cos2q I + sin2q k. Interpretations: 1. The quaternion operator qvq* has rotated the vector v counterclockwise (in the positive rotation sense), about k as an axis through an angle twice the quaternion’s angle while keeping the fixed the coordinate frame. This is called point or body rotation. OR: 2. The quaternion operator qvq* has rotated the coordinate frame (i, j, k) clockwise (in the negative rotation sense), about k as an axis through and angle - twice the quaternion’s angle while keeping fixed the vector v. This is called frame or global frame rotation. (In robotics the most common type of rotation is body rotation).

Quaternion and vectors: Exercise # 33 Example: Consider two unit quaternions p and q with both having the same unit vector u. Associated with p there is an angle a and associated with q there is an angle b. Prove that their product r = pq = cos g + u sin g is such that the unit vector is kept in the product and its angle is the sum of a and b, that is g = a + b. Proof: (See Notes 0b slide #3 for the trigonometry part ) We can write p = cos a + u sin a and q = cos b + u sin b. Then, we use the quaternion product rule to expand r = pq which yields r = pq = cos(a + b) + u sin(a + b) = cos g + u sin g. We proceed as follows: r = pq = (cos a + u sin a)(cos b + u sin b) = … Etc…

The Quaternion Rotation Operator General Formula There are known “forms” to express the rotation operator w = qvq* where v is the input vector and q is a quaternion with magnitude |q| = 1. We have: w = qvq* = (q0 + q)(0 + v)(q0 – q) = (2(q0)2 - |q|2)v + 2(q . v)q + 2q0(q x v) = (2(q0)2 - 1)v + 2(q . v)q + 2q0(q x v). which is equivalent to Rodrigues formula for rotations (verify it!). Similarly, for the other quaternion operator : w = q*vq = (q0 - q)(0 + v)(q0 + q) = (2(q0)2 - |q|2)v + 2(v . q)q + 2q0(v x q) = (2(q0)2 - 1)v + 2(v . q)q + 2q0(v x q). where each term in these expressions can be written in matrix form. The matrix expansions are: w = qvq* = Q v (the matrix Q is given in the next slide) and w = q*vq = Qt v

The unit quaternion rotations properties ROTATIONS DEFINED USING QUATERNIONS “For any unit quaternion q = q0 + q = cos q + u sin q and for any vector v  R3, the action operator Lq(v) = qvq* on v may be interpreted geometrically as a rotation of the vector v though an angle 2q about q as the axis of rotation”. (Additional Equations: |m| = |n| = |n| where: |n| = |n x u| = |n||u| sin(p/2) = |n| m = Lq(n) = ((q0)2 - |q|2)n + 2(q . n)q + 2q0 (q x n), that is: Lq(n) = ((q0)2 - |q|2)n + 2q0|q|n = (cos2 q - sin2 q)n + (2cos q sin q)n = (cos 2q )n + (sin 2q)n

The Quaternion Rotation Operator Matrix Formula We expand the terms in w = qvq* = Q v as follows: (2(q0)2 - 1) v = 2(q . v)q = 2q0(q x v) = v1 v2 v3 2(q0)2 – 1 0 0 0 2(q0)2 – 1 0 0 0 2(q0)2 – 1 v1 v2 v3 2(q1)2 2q2q1 2q3q1 2q1q2 2(q2)2 2q3q2 2q1q3 2q2q3 2(q3)2 v1 v2 v3 0 -2q0q3 2q0q2 2q0q3 0 -2q0q1 -2q0q2 2q0q1 0 therefore: w1 w2 w3 v1 v2 v3 2(q0)2 – 1 + 2(q1)2 2q2q1 – 2q0q3 2q3q1 + 2q0q2 2q1q2 + 2q0q3 2(q0)2 – 1 + 2(q2)2 2q3q2 – 2q0q1 2q1q3 – 2q0q2 2q2q3 + 2q0q1 2(q0)2 – 1 + 2(q3)2 = Q v = Lastly, w = q*vq = Qt v

The Quaternion Rotation Operator Matrix: Exercise # 34 Prove that any vector that lies on the axis of rotation is invariant, that is, if v = kq, then the rotation operator qvq* leaves the vector unchanged. Answer: We have (Verify it!): w = qvq = q(kq)q* = (2(q0)2 - 1)v + 2(q . v)q + 2q0(q x v) = (2(q0)2 - 1)(kq) + 2(q . kq)q + 2q0(q x kq) = k(q0)2 q – k|q|2q + 2k|q|2q = k((q0)2 + |q|2)q = k (1)q = kq = v

Rotation Examples: Exercise # 35 Exercise: Consider a rotation in R3 about an axis defined by the vector v = [1 1 1]t and the angle of rotation about the specified axis is f = 2p/3 = 120 degrees. Then, under this rotation, the vectors say ai becomes aj, bj becomes bk and ck becomes ci. Explain how this happens using quaternions. Answer: First we define the unit vector u in the direction of vector (1, 1, 1) as follows: u = [1/3 1/ 3 1/ 3] = i 1/3 + j 1/3 + k 1/3 Next, the appropriate angle q in the unit quaternion q is (1/2) of the angle of rotation, that is q = p/3 and thus q = cos q + u sin q = (1/2) + (i 1/3 + j 1/3 + k 1/3)(3/2)  q0 = 1/2 and q = (1/2)i + (1/2)j + (1/2)k. If we check the effect of the operator qvq* on, say, the vector v = i, it is easy to evaluate the terms q . i = 1/2 and q x i = (1/2)j – (1/2)k and lastly w = qiq* = j. It is a simple exercise to verify that the frame rotation operator w = q*iq = k.

Exercise #36: Exercise: Prove that RZ,a can be derived from the quaternions formula Hint: See slide #13 - use the Rodrigues formula qvq* = (2(q0)2 - 1)v + 2(q . v)q + 2q0(q x v). Proof: (Use trig formulas: cos(2q) = 2cos2 q - 1, 2 sin q cos q = sin 2q, sin2 q + cos2 q =1) In this case u = [0 0 1]t and q = q0 + q = cos a/2 + u sin a/2, therefore q0 = cos a/2, q1 = q2 = 0, q3 = sin a/2, therefore: RZ,a = Q = as expected!!! 2(q0)2 – 1 + 2(q1)2 2q2q1 – 2q0q3 2q3q1 + 2q0q2 2q1q2 + 2q0q3 2(q0)2 – 1 + 2(q2)2 2q3q2 – 2q0q1 2q1q3 – 2q0q2 2q2q3 + 2q0q1 2(q0)2 – 1 + 2(q3)2 2(q0)2 – 1 -2q0q3 0 2q0q3 2(q0)2 – 1 0 0 0 2( (q0)2 + (q3)2 ) - 1 cos a = 2cos2 (a/2) – 1 sin a = 2sin(a/2)cos(a/2) 1 = 2(cos2 (a/2) + (cos2 (a/2) ) - 1 , and since: cos a -sin a 0 sin a cos a 0 0 0 1