6

So I'm very new to quaternions, but I understand the basics of how to manipulate stuff with them. What I'm currently trying to do is compare a known quaternion to two absolute points in space. I'm hoping what I can do is simply convert the points into a second quaternion, giving me an easy way to compare the two.

What I've done so far is to turn the two points into a unit vector. From there I was hoping I could directly plug in the i j k into the imaginary portion of the quaternion with a scalar of zero. From there I could multiply one quaternion by the other's conjugate, resulting in a third quaternion. This third quaternion could be converted into an axis angle, giving me the degree by which the original two quaternions differ by.

Is this thought process correct? So it should just be [ 0 i j k ]. I may need to normalize the quaternion afterwards, but I'm not sure about that.

I have a bad feeling that it's not a direct mapping from a vector to a quaternion. I tried looking at converting the unit vector to an axis angle, but I'm not sure this would work, since I don't know what angle to give as an input.

Hmm
  • 71
  • 1
  • 2
  • 1
    This might be a better post for http://math.stackexchange.com/ or http://physics.stackexchange.com/. From what I understand (very limited!) quaternions are 4D complex numbers and are used to describe rotations. It's not obvious to me how they relate to vectors. – Daniel Farrell Jan 11 '11 at 23:18
  • Are you trying to use the quaternion to represent a rotation? If not, make it clear what are you trying to represent, because to compare positions vectors are better suited. By the way converting the tuple of vector and angle to quaternion is easy, bearing and elevation to quaternion is also easy. – Theraot Feb 01 '12 at 21:30

1 Answers1

1

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

Fred Klingener
  • 146
  • 1
  • 6
  • (X⊗Q)* = X*⊗Q is wrong, take X=j and Q=i+j, then X⊗Q=-k-1, (X⊗Q)*=-1+k, X*⊗Q = -(-k-1)=1+k. – Lutz Lehmann May 05 '14 at 10:13
  • Because the vector part of the quaternion transform Q12 is the axis about which the vector is rotated, it is mutually perpendicular to X1 and X2. So a proper demonstration with that constraint might be X = j and Q = i + k (it's unimportant for the demonstration that Q isn't a unit quaternion.) Q* ⊗ X* = - i + k, and the final result form X* ⊗ Q = - i + k. – Fred Klingener May 06 '14 at 19:48
  • OK, this was not as general as it seemed. But then you do not need the general square root, X2⊗X1*=X1⊗X2=C+S*n, where C= is the scalar product and S*n=X1×X2 is the cross product, S>=0 the norm of the cross product. Q=D+T*n by the previous steps and assumptions, so Q⊗Q=(D²-T²)+2*DT*n, which means that (D,T) is the half-angle point to (C,S), that is, D=√(0.5*(1+C)), T=√(0.5*(1-C)). – Lutz Lehmann May 06 '14 at 21:57