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)=ac−bd+(ad+bc)i
  • Conjugation: z=a+bi becomes z¯=a−bi. 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,v→1) and q2=(s2,v→2)

  • Multiplication: q1q2=(s1s2−v1⋅v2,s1v→2+s2v→1+v→1×v→2)
    • Order matters in quaternion multiplication!
  • Conjugation: q→=(s−v→), and ⟨qs¯⟩=s2+|v|2=|q|2
  • Inversion: q−1=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⁡(θ(1−t))q1+sin⁡(θt)q2sin⁡θ, where cos−1(q1⋅q2)=θ.

Other Graphics Uses for Quaternions

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