CSCE 441 Lecture 37

From Notes
Jump to navigation Jump to search

« previous | Wednesday, April 23, 2014 | next »


Quaternions and Complex Numbers

how they should be used.


Complex Numbers

Defined by a real and imaginary part:

a+bi, where i=1.

Simple operations:

  • (a+bi)+(c+di)=(a+c)+(b+d)i
  • a+bi(c+di)=acbd+(ad+bc)i
  • Conjugation: z=a+bi becomes z¯=abi. What's impressive about this is that zz¯=a2+b2=|z|2, where |z|=a2+b2

Relation to Graphics

Given a point (x,y), rotate that point about the origin by θ:

[x^y^]=[cosθsinθsinθcosθ][xy]


Represent (x,y) by a complex number: (x+yi)


(x+yy)(cosθ+isinθ)=(xcosθysinθ)+(xsinθ+ycosθ)i

Rotation is just multiplication by a complex number.


Quaternions

Sir William Rowan Hamilton attempted to extend complex numbers from 2D to 3D, but this is now provably impossible. He discovered a generalization to 4D and wrote it on the side of a bridge in Dublin.

One real part, 3 complex parts:

i2=j2=k2=ijk=1

From this, we get

  • ij=k
  • ji=k
  • jk=i
  • kj=i
  • ki=j
  • ik=j


q=(s,v)=s+vxi+vyj+vzk

We can define an algebra on

q1=(s1,v1) and q2=(s2,v2)

  • Multiplication: q1q2=(s1s2v1v2,s1v2+s2v1+v1×v2)
    • Order matters in quaternion multiplication!
  • Conjugation: q=(sv), and qs¯=s2+|v|2=|q|2
  • Inversion: q1=q¯|q|


Relation to Graphics

Claim: unit quaternions represent 3D rotation

Convert from 3D to 4D: p=(0,r), where r=x,y,z.


q=(cosθ,sinθv), where |v|=1.

let v be parallel to the axis of rotation in 3D.

In this case, pq=qp=(sinθ,cosθv). This gives a nonzero real component... uh oh, we now have a 4D number, not a 3D number.

let v be a vector component in the plane normal to r:

qp represents a positive (ccw) rotation, and pq represents a negative (cw) rotation.


Computing qpq¯ rotates the component of v perpendicular to r by 2θ and leaves the parallel component alone.

Thus the quaternion representing rotation about the unit axis v by θ is
q(0,r)q¯, where q=(cos(θ2),sin(θ2)v)


Quaternions vs. Matrices

This seems like magic... This is perhaps the wrong use for quaternions

  • Quaternions take less space (4 vs. 9)
  • Rotating a vector requires 28 multiplications using quaternions vs. 9 for matrices
  • Composing two rotations using quaternions q1q2 requires 16 multiplications vs. 27 for matrices
  • Quaternions are not hardware-accelerated whereas matrices are.

Quaternions and Interpolation

Unit quaternions represent points on a 4D hypersphere

Interpolation on the sphere gives rotations that bend the least.

Recall we used SLERP to interpolate vectors on the surface of a 3D sphere.


May need to interpolate between q1 and q2.

q(t)=sin(θ(1t))q1+sin(θt)q2sinθ, where cos1(q1q2)=θ.

Other Graphics Uses for Quaternions

Skeletal animation: moving bones usually requires a lot of composed rotations.