Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Given a 3-variable right-handed vector v that is a translation measured in local space and a unit quaternion representing an orientation from local to world space, how do you use the quaternion to rotate the vector from local space to world space?

For ease of use, the values are:

Vector v = $[1.0, 0.0, 0.0]$

Quaternion $q = [W: 0.7071068, X: 0, Y: 0.7071068, Z: 0]$, which I understand to be a rotation $90^\circ (\frac{\pi}{2})$ around the $Y$-axis and which converts from the local space to the world space. (That is, the resulting vector is $[0.0, 0.0, 1.0]$, and if this was the nose of a spaceship, it'd be pointing to the right in world coordinates)

Thanks.

share|improve this question
    
@Narf: In response to your previous question, I'd linked to this Wikipedia article in my answer: en.wikipedia.org/wiki/Quaternions_and_spatial_rotation. Could you say more specifically what part of the explanation there you don't understand? –  joriki May 19 '11 at 22:45
    
I'm not rotating the quaternion; I'm rotating the vector. Seems like it'd be a different thing. –  Narf the Mouse May 20 '11 at 15:02
    
@Narf: No, that's exactly what's described there; I'd even linked to the relevant section of the article in my answer to your previous question: en.wikipedia.org/wiki/… –  joriki May 20 '11 at 22:46
    
@joriki, how is v' = qv(q^-1) represented in terms of the x, y, z coordinates in the vector v in relation to the w, x, y, z coordinates in the Quaternion for a rotation of v by q. –  Daniel Jun 3 '11 at 12:01
    
@Daniel: If I understand your question correctly, again, the answer is right there in the Wikipedia article I twice linked to: "Let also $\vec{v}$ be an ordinary vector in 3-dimensional space, considered as a quaternion with a real coordinate equal to zero." –  joriki Jun 4 '11 at 13:09
show 1 more comment

2 Answers

up vote 9 down vote accepted

You seem to be having a good deal of trouble with this, over several questions. At the same time, I am confident that you will get no satisfying answers as long as you stick with the terminology you are using. Maybe on the original stack overflow site, aimed at programmers.

Please read this: http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

and this: http://en.wikipedia.org/wiki/Quaternions

To answer not much more than your question, any quaternion is an expression $$ q = w + x \; \mathbf{i} + y \; \mathbf{j} + z \; \mathbf{k}.$$ where the multiplication rules use $$ \mathbf{i}^2 = \mathbf{j}^2 = \mathbf{k}^2 = \mathbf{i} \mathbf{j}\mathbf{k} = -1, $$ and consequences of those, see wikipedia as I said. Any quaternion $ q = w + x \; \mathbf{i} + y \; \mathbf{j} + z \; \mathbf{k}$ has a conjugate, that on wikipedia is written $q^\ast,$ given by $$ q^\ast = w - x \; \mathbf{i} - y \; \mathbf{j} - z \; \mathbf{k}.$$

The "norm" of the quaternion $q$ is exactly $$ \parallel q \parallel^2 = w^2 + x^2 + y^2 + z^2 = q q^\ast = q^\ast q$$

A quaternion $q$ is called a "unit" quaternion when $$ w^2 + x^2 + y^2 + z^2 = 1. $$

A quaternion is called "pure" or a vector in 3-space when $ w = 0,$ so a vector in 3-space is $$ v = v_1 \; \mathbf{i} + v_2 \; \mathbf{j} + v_3 \; \mathbf{k} $$ I have no idea what engineers and programmers call these concepts. You are asking mathematicians.

Given two quaternions, the norm of the product is the product of the norms.

The "real part" (the $w$) of the product of two quaternions $pq$ is the same as the "real part of $qp.$

So, what happens when I take a unit quaternion $q$ and a "pure" quaternion $v,$ and calculate $$ p = q^\ast v q.$$

Well, we have $$\parallel p \parallel = 1 \cdot \parallel v \parallel \cdot 1 = \parallel v \parallel $$

But as to the "real part," we begin with $$ \Re v = 0,$$

then $$ \Re q^\ast (v q) = \Re (v q) q^\ast = \Re v (q q^\ast) = \Re v = 0. $$

So $ p = q^\ast v q$ is another pure quaternion, another "vector," the same length as $v,$ but rotated from where it was.

That's enough for a start.

share|improve this answer
1  
Again, I'm not asking how to rotate a quaternion by a vector this time; I'm asking how to rotate a vector by a quaternion, resulting in a vector pointing in a different direction. –  Narf the Mouse May 20 '11 at 15:04
    
Since the "vector" in your question has three coordinates, just put a 0 in front to get a pure quaternion. –  Will Jagy May 21 '11 at 17:59
    
Just to clarify; to rotate the 3D vector "v" (that has a x,y,z and a non-existent real coordinate of 0), what is the x, y and z coordinates equal to in terms of the quaternions values (x,y,z and w). For example, for a quaternion "q" if I wanted to determine v.x (imagine subscript), it might be v.x = q.w + q.z etc. I don't understand how p = q*v*q or the wiki formula: v' = qv(q^-1) helps at all. –  Daniel Jun 3 '11 at 11:31
    
Ok, thanks. Sorry for the long delay, but life. I'm marking yours as the answer. –  Narf the Mouse Jun 4 '11 at 18:25
2  
Of course he knew what the OP was asking. The OP was the only one having trouble understanding that he was being given answers that were valid; he was getting hung up on terminology, and Will Jagy merely pointed that out and offered resources to try to clear up that confusion. –  Muphrid Oct 22 '13 at 2:46
show 2 more comments

The simple answer to the question is, given:

 R = [w, x, y, z]  
 P = [0, p1, p2, p2]
 R' = [w, -x, -y, -z] 

You can calculate the resulting vector using the hamilton product H(a, b) (described here: http://en.wikipedia.org/wiki/Quaternion#Hamilton_product) by:

 P' = RPR'
 P' = H(H(R, P), R')

In the example given these are:

 R = [0.7071203316249954, 0.0, 0.7071203316249954, 0.0]
 R' = [0.7071203316249954, 0.0, -0.7071203316249954, 0.0]
 P = [0, 1, 0, 0]
 H(R, P) = [0.0, 0.7071203316249954, 0.0, -0.7071203316249954]
 H(H(R, P), R') = [0.0, 0.0, 0.0, -1.0000383267948871]

Notice the result is a length 4 vector; the w component will always be zero and can be discarded.

Ie. The point (1, 0, 0) is transformed by a rotation around the Y-axis by 90 degrees and becomes (0, 0, -1)

For those unfamiliar with quaternions, it's worth noting that the quaternion R is generated as described here (http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation):

a = angle to rotate
[x, y, z] = axis to rotate around

R = [cos(a/2), sin(a/2)*x, sin(a/2)*y, sin(a/2)*z]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.