Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Quaternion representing rotation from one coordinate system to another

I am getting a quaternion from sensor data that is in the coordinate system Y=up, X=right, and Z= backwards.Mine is X=forward, Y=right, Z=up.

So OX=Y, OY=Z and OZ=-X.

I have a function that can convert quaternions into 4by4 matrices, but no idea where to go from here. Any help would be greatly appreciated.

like image 760
Craig Delancy Avatar asked Sep 15 '13 22:09

Craig Delancy


People also ask

How do you rotate a quaternion by another quaternion?

Use the Quaternion operator * . In Unity, when you multiply two quaternions, it applies the second quaternion (expressed in global axes) to the first quaternion along the local axes produced after the first Quaternion ).

How do you convert a rotation matrix to a quaternion?

quat = rotm2quat( rotm ) converts a rotation matrix, rotm , to the corresponding unit quaternion representation, quat . The input rotation matrix must be in the premultiply form for rotations.


2 Answers

Quaternions in the form of [X, Y, Z, W] are equivalent to axis-angle rotations where W is dependent only on the angle of rotation (but not the axis) and X, Y, Z are the axis of rotation multiplied by sin(Angle/2). Since X, Y, Z have this property, you can just swap and negate them as you would to convert a 3D coordinate between. To convert from your sensor's coordinate system to yours, you can simply do this:

MyQuat.X = -SensorQuat.Z
MyQuat.Y = SensorQuat.X
MyQuat.Z = SensorQuat.Y
MyQuat.W = SensorQuat.W
like image 196
mkimball Avatar answered Nov 13 '22 00:11

mkimball


Assume you have two coordinate systems F1 and F2. For simplicity, assume both have same origin. Now let,

qo_f1 = orientation of frame F1 as seen from frame F2
qo_f2  = orientation of frame F2 is as seen from F1
q_f1 = some quaternion in F1 frame
q_f2 = q_f1 as seen from F2

Then,

q_f2 = qo_f2 * q_f1 * qo_f2.inverse()

Explanation

To rotate anything by quaternion q you just do q*p*q.inverse(). If p is a vector then you first convert it to "fake" quaternion by setting w=0 and x,y,z same as vector. If p is quaternion then you are good to go.

like image 20
Shital Shah Avatar answered Nov 13 '22 00:11

Shital Shah