Convert a Unit Vector to a Quaternion

核能气质少年 提交于 2019-12-05 06:22:39

Notation

Quaternions are defined in a four-space with bases {1, i, j, k}. Hamilton famously carved the fundamental relationship into the stone of the Brougham Bridge in Dublin:

i2 = j2 = k2 = i j k = -1.

There are many equivalent quaternion parameterizations, but here I'll use a {scalar, vector} form.

1.) A = {a0, a} and B = {b0, b}, where A and B are quaternions, a0 and b0 are scalars, and a and b are three-vectors.

2.) X = { 0, x } is a vector quaternion.

3.) The (non-commutative) quaternion product derives directly from the properties of i, j and k above, A⊗B = {a0 b0 - a.b, a0 b + b0 a + a x b}

4.) The quaternion conjugate is A* = {a0, - a}

5.) The conjugate of a quaternion product is the product of the conjugates in reverse order.
(A⊗B)* = B*⊗A*

6.) The conjugate of a vector quaternion is its negative. X* = {0, -x } = -X

7.) The quaternion norm is |A| = √(A⊗A*) = √( a0² + a.a )

8.) A unit quaternion is one that has a norm of 1.

9.) A unit three-vector x = {x1, x2, x3} with x . x = 1 is expressible as a unit vector quaternion X = { 0, x }, |X| = 1.

10.) The spherical rotation of a quaternion vector X by an angle θ about a unit vector axis n is Q⊗X⊗Q*, where Q is the quaternion {cos(θ/2), sin(θ/2) n }. Note that |Q| = 1.

Notice the form of the quaternion vector product. Given vector quaternions X1 = { 0, x1 ) and X2 = { 0, x2 }, the quaternion product is X2⊗X1* = { x1.x2, x1 × x2 }. The quaternion reunites the dot product as the scalar part and cross product as the vector part, divorced over a hundred years ago. Neither of these products is invertible, but the quaternion is in the way described below.

Inversion

Find the spherical transform quaternion Q12 to rotate vector X1 to align with vector X2.

From above

X2 = Q12⊗X1⊗Q12*

Multiplying both sides by X1*,

X2⊗X1* = Q12⊗X1⊗(Q12*⊗X1*)

Remember that the rotation axis n derives from the cross product x1×x2, so n . x1 = 0. and Q*⊗X* = (X⊗Q)* = X*⊗Q, leaving

X2⊗X1* = Q12⊗X1⊗X1*⊗Q12 = Q12⊗Q12

So the quaternion transform can be solved directly as

Q12 = √(X2⊗X1*)

You're on your own for the quaternion square root. There are lots of ways to do it, and the best will depend on your application, considering speed and stability.

--hth,
Fred Klingener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!