Problem 6

Quaternion package

<<Algebra`Quaternions`

norm[v_] := Sqrt[v . v] ;

equivAngleAxis[q_] := <br />    Module[{ql, s, v}, <br />    ...  1] ; <br />         {2 ArcTan[ s, norm[v]], v/norm[v]}] ;

Definition of distance metric

e[q_, p_] := Sqrt[((List @@ q) - (List @@ p)) . ((List @@ q) - (List @@ p))] ;

d[q_, p_] := Min[e[q, p], e[q, -p]] ;

Part (a)

See solutions text.

Part (b)

See solutions text.

Part (c)

Here are the quaternions:

q = Quaternion[1/2^(1/2), 0, 1/2^(1/2), 0] ; qp = Quaternion[1/4 (-1 + 6^(1/2)), 0, 1/4 (1 + 6 ... 6 (-2 + 3^(1/2) - 6^(1/2)), 1/32 (6 + 11 2^(1/2) + 4 3^(1/2) - 6^(1/2)), 1/16 (-1 + 4 6^(1/2))] ;

Let's just verify that they are unit quaternions:

Abs[q]

1

Abs[qp] // Simplify

1

Abs[qpp] // Simplify

1

Now let's compute the distances:

d1 = d[q, qp] // Simplify

(2 - 3^(1/2))^(1/2)

d1 // N

0.517638

d2 = d[qp, qpp] // Simplify

(2 - 3^(1/2))^(1/2)

d2 // N

0.517638

d3 = d[q, qpp] // Simplify

1/2 (1/2 (6 + 3^(1/2)))^(1/2)

d3 // N

0.983111

Now, let's verify that these numbers obey the triangle inequality:

d[q, qp] + d[qp, qpp] >= d[q, qpp]

True

d[qp, qpp] + d[qpp, q] >= d[qp, q]

True

d[qp, q] + d[q, qpp] >= d[qp, qpp]

True

Part (d)

r1 = (qp^-1) ** q // FullSimplify

Quaternion[3^(1/2)/2, 1/4, -1/(2 2^(1/2)), -1/4]

r1 // N

RowBox[{Quaternion, [, RowBox[{0.866025, ,, 0.25, ,, RowBox[{-, 0.353553}], ,, RowBox[{-, 0.25}]}], ]}]

{θ1, k1} = equivAngleAxis[r1]

{π/3, {1/2, -1/2^(1/2), -1/2}}

{θ1, k1} // N

RowBox[{{, RowBox[{1.0472, ,, RowBox[{{, RowBox[{0.5, ,, RowBox[{-, 0.707107}], ,, RowBox[{-, 0.5}]}], }}]}], }}]

r2 = (qpp^-1) ** qp // FullSimplify

Quaternion[3^(1/2)/2, 1/32 (8 - 3 2^(1/2) + 3^(1/2) + 6^(1/2)), 1/32 (-2 2^(1/2) - 2 3^(1/2) - 3 6^(1/2)), 1/32 (-4 - 3 2^(1/2) - 3^(1/2) + 3 6^(1/2))]

r2 // N

RowBox[{Quaternion, [, RowBox[{0.866025, ,, 0.248091, ,, RowBox[{-, 0.426281}], ,, RowBox[{-, 0.0820694}]}], ]}]

{θ2, k2} = equivAngleAxis[r2] // FullSimplify

{π/3, {1/16 (8 - 3 2^(1/2) + 3^(1/2) + 6^(1/2)), 1/16 (-2 2^(1/2) - 2 3^(1/2) - 3 6^(1/2)), 1/16 (-4 - 3 2^(1/2) - 3^(1/2) + 3 6^(1/2))}}

{θ2, k2} // N

RowBox[{{, RowBox[{1.0472, ,, RowBox[{{, RowBox[{0.496181, ,, RowBox[{-, 0.852562}], ,, RowBox[{-, 0.164139}]}], }}]}], }}]

r3 = (qpp^-1) ** q // FullSimplify

Quaternion[5/8 - 3^(1/2)/16, 1/32 (2^(1/2) + 10 3^(1/2) - 6^(1/2)), 1/16 (-1 - 3 2^(1/2) - 2 6^(1/2)), 1/32 (3 2^(1/2) - 3^(1/2) (6 + 2^(1/2)))]

r3 // N

RowBox[{Quaternion, [, RowBox[{0.516747, ,, 0.508913, ,, RowBox[{-, 0.633851}], ,, RowBox[{-, 0.268724}]}], ]}]

{θ3, k3} = equivAngleAxis[r3] // FullSimplify

{2 ArcCot[(10 - 3^(1/2))/(153 + 20 3^(1/2))^(1/2)], {(2^(1/2) + 10 3^(1/2) - 6^(1/2))/(2 (153  ... 1/2))/(153 + 20 3^(1/2))^(1/2), -(-3 2^(1/2) + 6 3^(1/2) + 6^(1/2))/(2 (153 + 20 3^(1/2))^(1/2))}}

{θ3, k3} // N

RowBox[{{, RowBox[{2.0555, ,, RowBox[{{, RowBox[{0.594429, ,, RowBox[{-, 0.740361}], ,, RowBox[{-, 0.313879}]}], }}]}], }}]

Note that the distance measure seems to be correlated to the angle of rotation between two quaternions. From q to qp, and qp to qpp, the rotation angle between them is the same (π/3), as is the distance measure. The rotation angle between q and qpp is almost twice as large as between q and qp, as is the distance measure. Therefore, the distance measure appears to be strongly related to the angle of rotation between two quaternions.

Part (e)

Let us assign the following three quaternions q, p and u. We will proceed by first showing that the distance measure between u (the zero-rotation unit quaternion) and an arbitrary quaternion p depends only on the rotation angle θ. We will then generalize this result by rotating both p and u by an arbitrary quaternion q, and showing that the distance measure remains the same.

q = Quaternion[s, x, y, z]

Quaternion[s, x, y, z]

θ=. ; p = Quaternion[Cos[θ/2], Sin[θ/2] kx, Sin[θ/2] ky, Sin[θ/2] kz]

Quaternion[Cos[θ/2], kx Sin[θ/2], ky Sin[θ/2], kz Sin[θ/2]]

u = Quaternion[1, 0, 0, 0]

Quaternion[1, 0, 0, 0]

res1 = d[u, p] // FullSimplify

Min[((-1 + Cos[θ/2])^2 + (kx^2 + ky^2 + kz^2) Sin[θ/2]^2)^(1/2), ((1 + Cos[θ/2])^2 + (kx^2 + ky^2 + kz^2) Sin[θ/2]^2)^(1/2)]

res1a = ExpandAll[(res1 /. {(kx^2 + ky^2 + kz^2) -> 1})]   

Min[(1 - 2 Cos[θ/2] + Cos[θ/2]^2 + Sin[θ/2]^2)^(1/2), (1 + 2 Cos[θ/2] + Cos[θ/2]^2 + Sin[θ/2]^2)^(1/2)]

res1a = res1a /. {Cos[θ/2]^2 + Sin[θ/2]^2 -> 1}

Min[(2 - 2 Cos[θ/2])^(1/2), (2 + 2 Cos[θ/2])^(1/2)]

res1b = res1a // FullSimplify

Min[2 Cos[θ/4]^2^(1/2), 2 Sin[θ/4]^2^(1/2)]

Plot[res1b, {θ, 0, 2Pi}] ;

[Graphics:../HTMLFiles/index_104.gif]

The two results (res1a and res1b)  above give  two  equivalent expressions for  d(u, p). The graph above plots this for θ ranging from 0 to 2π. Note that the distance measure reaches a peak at θ=π. What remains is to show that this result does not change if we multiply both u and p by an arbitrary unit quaternion q.

p1 = q ** p

Quaternion[s Cos[θ/2] - kx x Sin[θ/2] - ky y Sin[θ/2] - kz z Sin[θ/2], x C ... x z Sin[θ/2], z Cos[θ/2] + kz s Sin[θ/2] + ky x Sin[θ/2] - kx y Sin[θ/2]]

p2 = q ** u

Quaternion[s, x, y, z]

res2 = d[p1, p2]

Min[√ ((-z + z Cos[θ/2] + kz s Sin[θ/2] + ky x Sin[θ/2] - kx y Sin[θ ... ;/2])^2 + (s + s Cos[θ/2] - kx x Sin[θ/2] - ky y Sin[θ/2] - kz z Sin[θ/2])^2)]

res2 = res2 // FullSimplify

Min[((s^2 + x^2 + y^2 + z^2) ((-1 + Cos[θ/2])^2 + (kx^2 + ky^2 + kz^2) Sin[θ/2]^2))^ ... ), ((s^2 + x^2 + y^2 + z^2) ((1 + Cos[θ/2])^2 + (kx^2 + ky^2 + kz^2) Sin[θ/2]^2))^(1/2)]

res2 = res2 /. (s^2 + x^2 + y^2 + z^2) -> 1

Min[((-1 + Cos[θ/2])^2 + (kx^2 + ky^2 + kz^2) Sin[θ/2]^2)^(1/2), ((1 + Cos[θ/2])^2 + (kx^2 + ky^2 + kz^2) Sin[θ/2]^2)^(1/2)]

res2 = res2 //. (kx^2 + ky^2 + kz^2) -> 1

Min[((-1 + Cos[θ/2])^2 + Sin[θ/2]^2)^(1/2), ((1 + Cos[θ/2])^2 + Sin[θ/2]^2)^(1/2)]

res2 = res2 // FullSimplify

Min[2 Cos[θ/4]^2^(1/2), 2 Sin[θ/4]^2^(1/2)]

Note that this result is, as expected identical, to the previous result and shows that the distance measure is dependent only on the angle of rotation θ between two unit quaternions.

Part (f)

We will use the result from part (e) to illustrate the triangle inequality. Consider three unit quaternions q, q' and q''. Let q and q' be separated by an angle of rotation θ1, and let q' and q'' be separated by an angle of rotation θ2. Also define d(θ) = distance measure for two unit quaternions separated by an angle of rotation θ. Then, all that needs to be shown is that d(θ1) + d(θ2) >= d(θ1 + θ2) for all θ1, θ2, or alternatively that f(θ1, θ2) = d(θ1) + d(θ2) - d(θ1 + θ2) >= 0. This is most easily shown graphically.

d[θ_] := Min[2 Abs[Cos[θ/4]], 2 Abs[Sin[θ/4]]] ;

f[θ1_, θ2_] := d[θ1] + d[θ2] - d[θ1 + θ2] ;

Plot3D[f[θ1, θ2], {θ1, 0, 2Pi}, {θ2, 0, 2Pi}, PlotPoints->30] ;

[Graphics:../HTMLFiles/index_122.gif]

ContourPlot[f[θ1, θ2], {θ1, 0, 2Pi}, {θ2, 0, 2Pi}, PlotPoints->50, Contours->20, PlotRange->All] ;

[Graphics:../HTMLFiles/index_124.gif]

Note from the two plots, that f(θ1, θ2) is always greater than zero.


Created by Mathematica  (September 29, 2003)