Question

The following image shows two coordinate systems A and B, positioned in the global frame G: coordinate systems configuration

I need to find quaternion which rotates A to B, but expressed in the frame local to A.

The first part is easy, B.conjugate()*A (subtracting the rotation of B from the rotation of A), which gives π/2 rotation around (-1,0,0). That is obviously correct, since rotating A around the global -x axis by 90° gives B.

Now I need to express that result in the A; the desired result is π/2 around (0,0,-1) (that's what global -x is in A), but I am not able to get there just with rotation composition.

I can convert the quaternion to angle-axis representation (π/2 around (-1,0,0)), rotate the axis as A*(-1,0,0)=(0,0,-1), and convert back to quaternion, but I would like to avoid that conversion if possible.

How to get the rotation using quaternion multiplication only?


The code itself is c++, but I check that in python with minieigen:

from minieigen import *
from math import *
A=Quaternion((0,-1,0),pi/2)
B=Quaternion((sqrt(3)/3,-sqrt(3)/3,sqrt(3)/3),(2/3.)*pi)
# rotation in global frame:
rg=B.conjugate()*A           # is Quaternion((-1,0,0),pi/2)
# rotation in local frame:
# ?? what now?! hack around with angle-axis
aa=rg.toAngleAxis()
rl=Quaternion(A*aa[1],aa[0]) # is Quaternion((0,0,-1),pi/2)

for q in A,B,rg,rl: print q

which gives:

Quaternion((0,-1,0),1.5707963267948966)
Quaternion((0.5773502691896257,-0.5773502691896257,0.5773502691896257),2.0943951023931953)
Quaternion((-1,-7.850462293418876e-17,-7.850462293418876e-17),1.5707963267948968)
Quaternion((-1.1102230246251568e-16,-7.850462293418877e-17,-1),1.5707963267948968)
Was it helpful?

Solution

That was an easy one, but I leave it here for the record:

A*B.conjugate()

OTHER TIPS

Your equations don't quite sit right with me.

I'll use Q' for Q.conjugate. Now we know that Q'*Q is the identity and so it Q*Q'. Therefore, if you want to know the quaternion that transforms A into B (in the global frame since A and B are both in the global frame), then you start with that equation (assuming that these quaternions represent rotations applied to column vectors):

Q*A=B

then you move A over to the other side

Q*A*A'=B*A'=Q

This, we can see is correct, because B*A'*A=B. The equation in your questions says, that B'*A*A=B. This doesn't hold true in general, I think.

Now, if you want the rotation to be in A's frame instead of the global frame, that's equivalent to saying that you want B, in A's frame. That's the same as removing A from B. Like so: A'*B. This way, if you rotate from A's frame to the global frame, you end up with B again: A*A'*B=B.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top