Unit Quaternion 3D Rotation Representation

Introduction

In my previous article “Axis/Angle 3D Rotation Representation”, we have learned the axis/angle 3D rotation representation, there is another commonly used representation which is called unit quaternion 3D rotation representation.

In this blog post, I would like to discuss the quaternion 3D rotation representation and derive some of its properties mathematically.

Axis/Angle Rotation Representation

Here is a quick recovery from my previous article “Axis/Angle 3D Rotation Representation” on the axis/angle rotation representation.

R(n^,θ)=I+[n^]×sinθ+[n^]×2(1cosθ)

where the unit rotation vector n^=(n^1,n^2,n^3) and n^=n^12+n^22+n^32=1 and

[n^]×=[0n^3n^2n^30n^1n^2n^10]

Quaternion Rotation Representation

The quaternion rotation representation is closely related to the axis/angle rotation representation. The two representations could be converted from each other.

q=(x,y,z,w)=(v,w)=(n^sinθ2,cosθ2)=(n^1sinθ2,n^2sinθ2,n^3sinθ2,cosθ2)

where

x=n^1sinθ2y=n^2sinθ2z=n^3sinθ2w=cosθ2

It is easy to verify that q is a unit vector.

q=n^2sin2θ2+cos2θ2=sin2θ2+cos2θ2=1

Quaternion

Quaternion

Because sinθ=2sinθ2cosθ2 and 1cosθ=2sin2θ2,

R(n^,θ)=I+[n^]×sinθ+[n^]×2(1cosθ)=I+[n^]×(2sinθ2cosθ2)+[n^]×2(2sin2θ2)=I+2w([n^]×sinθ2)+2([n^]×sinθ2)2

We define a new matrix [v^]×,

[v^]×=[n^]×sinθ2=[0n^3sinθ2n^2sinθ2n^3sinθ20n^1sinθ2n^2sinθ2n^1sinθ20]=[0zyz0xyx0]

Thus,

[v^]×2=[0zyz0xyx0][0zyz0xyx0]=[y2z2xyxzxyx2z2yzxzyzx2y2]

Therefore, the rotation matrix could be expressed using q=(x,y,z,w).

R(n^,θ)=I+2w([n^]×sinθ2)+2([n^]×sinθ2)2=I+2w[v^]×+2[v^]×2=[12(y2+z2)2(xyzw)2(xz+yw)2(xy+zw)12(x2+z2)2(yzxw)2(xzyw)2(yz+xw)12(x2+y2)]

Formally, the rotation matrix R(q) could be expressed as

R(q)=[12(y2+z2)2(xyzw)2(xz+yw)2(xy+zw)12(x2+z2)2(yzxw)2(xzyw)2(yz+xw)12(x2+y2)]

Notice that

12(y2+z2)=(1(y2+z2))(y2+z2)=(1sin2θ2(n^22+n^32))(y2+z2)=(1sin2θ2(1n^12))(y2+z2)=(1sin2θ2+sin2θ2n^12)(y2+z2)=(cos2θ2+sin2θ2n^12)(y2+z2)=w2+x2y2z2

Similarly,

12(x2+z2)=w2+y2x2z2

12(x2+y2)=w2+z2x2y2

So the rotation matrix R(q) could also be expressed as

R(q)=[w2+x2y2z22(xyzw)2(xz+yw)2(xy+zw)w2+y2x2z22(yzxw)2(xzyw)2(yz+xw)w2+z2x2y2]

Quaternion Algebra and Properties

Identity Quaternion

It is easy to find that the identity quaternion is q=(0,1)=(0,0,0,1).

Antipodal Quaternion

Quaternion q=(v,w)=(x,y,z,w) and its antipodal quaternion q=(v,w)=(x,y,z,w) represent the same rotation, because it is easy to find that the rotational matrices R(q) and R(q) are exactly the same, i.e., R(q)=R(q).

Quaternion Multiplication

Suppose q0=(v0,w0)=(x0,y0,z0,w0), q1=(v1,w1)=(x1,y1,z1,w1), q2=(v2,w2)=(x2,y2,z2,w2), quaternion multiplication is defined as follows

q2=q0q1=(v0×v1+w0v1+w1v0,w0w1v0v1)

It carries the property that R(q2)=R(q0)R(q1), which means quaternion multiplication is just applying two rotations q1 and q0 sequentially (not q0 and q1!). The verification of this property is skipped in this article as the algebra is too complex.

Concretely,

q2=q0q1=(v0×v1+w0v1+w1v0,w0w1v0v1)=((y0z1z0y1,z0x1x0z1,x0y1y0x1)+(w0x1,w0y1,w0z1)+(w1x0,w1y0,w1z0),w0w1(x0x1+y0y1+z0z1))=(x2,y2,z2,w2)

where

x2=y0z1z0y1+w0x1+w1x0y2=z0x1x0z1+w0y1+w1y0z2=x0y1y0x1+w0z1+w1z0w2=w0w1x0x1y0y1z0z1

Notice that quaternion Multiplication is not communicative, i.e., usually q0q1q1q0, simply because the rotation axis of the two rotations could be different. In addition, quaternion multiplication with identity quaternion does not change the quaternion, i.e., qq0=q0q=q, when q0=(0,1).

Inverse Quaternion

Quaternion q=(v,w)=(x,y,z,w) and its inverse quaternion q1 cancel each other.

From my previous article “Axis/Angle 3D Rotation Representation”, we already know that (n^,θ) or (n^,θ) cancels (n^,θ). Because the axis/angle representation (n^,θ) corresponds to the quaternion representation (v,w)=(x,y,z,w), (n^,θ) corresponds to (v,w)=(x,y,z,w), (n^,θ) corresponds to (v,w)=(x,y,z,w), we could say (v,w) cancels (v,w). Therefore, q1=(v,w)=(x,y,z,w).

In fact, (n^,2πθ) also cancels (n^,θ), the axis/angle representation (n^,2πθ) corresponds to the quaternion representation (v,w)=(x,y,z,w). Therefore, q1=(v,w)=(x,y,z,w).

Taken together, there could be at least two expressions for the inverse quaternion q1, q1=(v,w)=(x,y,z,w) or q1=(v,w)=(x,y,z,w).

Suppose we used the inverse quaternion expression q1=(v,w)=(x,y,z,w), let’s verify if rotation q1=(x,y,z,w) cancels rotation q=(v,w)=(x,y,z,w).

R(q1)=[12(y2+z2)2(xy+zw)2(xzyw)2(xyzw)12(x2+z2)2(yz+xw)2(xz+yw)2(yzxw)12(x2+y2)]=R(q)

From my previous article “Axis/Angle 3D Rotation Representation”, we can know that R(q) is orthonormal and R(q)=R(q)1. Therefore,

R(q1)=R(q)=R(q)1

So,

R(q1)R(q)=I

Similarly, we could also show that rotation q1=(v,w)=(x,y,z,w) cancels rotation q=(v,w)=(x,y,z,w).

Notice that qq1=q1q=(0,1)=(0,0,0,1).

Quaternion Division

Suppose q0=(v0,w0)=(x0,y0,z0,w0), q1=(v1,w1)=(x1,y1,z1,w1), q2=(v2,w2)=(x2,y2,z2,w2), quaternion division is defined as follows

q2=q0q1=q0q11=(v0×v1+w0v1w1v0,w0w1v0v1)=(v0×v1w0v1+w1v0,w0w1+v0v1)

Spherical Linear Interpolation

In some scenarios, we would like to compute a rotation that is in the pathway of two rotations. This procedure is called spherical linear interpolation or slerp for short.

Suppose we have two rotations using unit quaternion representation, q0 and q1, we would like to compute the rotation q2 that is α partway of the two rotations. The key to this procedure is to compute the rotation angle θr between the two rotations.

Suppose q1=qrq0, i.e., q1 is applying q0 followed by qr, and q2=qαq0. Because

q1q01=qrq0q01=qr(0,1)=qr

Using quaternion division, we could compute qr,

qr=q1q01=(vr,wr)

We want to make sure that π2θr2π2, i.e., wr0. There are chances wr<0, we could just apply the antipodal quaternion property and flip the quaternion qr, i.e., qrq. After all qr and qr represent the same rotation.

Because vr=sinθr2 and wr=cosθr2

tanθr2=sinθr2cosθr2=vrwr

θr could be computed using

θr=2arctan(vrwr)

The fraction of the rotation angle θα is therefore

θα=αθr

The unit rotation axis could also be computed using

n^r=(n^r,1,n^r,2,n^r,3)=(n^r,1sinθr2,n^r,2sinθr2,n^r,3sinθr2)sinθr2=vrvr

Thus, by the definition of quaternion,

qα=(n^rsinθα2,cosθα2)

q2=qαq0

Unit Quaternion 3D Rotation Representation

https://leimao.github.io/blog/3D-Rotation-Unit-Quaternion/

Author

Lei Mao

Posted on

04-24-2022

Updated on

04-24-2022

Licensed under


Comments