Convert quaternion from right to left coordinate system

I [0.130526, 0.0, 0.0, 0.991445] my 3d program, the rotation of the object is represented by a quaternion like [0.130526, 0.0, 0.0, 0.991445] . The program works with the right coordinate system with the Z axis pointing up (as in 3ds max):

enter image description here

On the other hand, my application uses the left coordinate system , and the Y axis is up :

enter image description here

How can I convert my quaternion from one coordinate system to another with respect to which axis up?

+9
source share
2 answers

The rotation of the angle x around the axis (u, v, w) can be represented by a quaternion with the real part cos (x / 2) and the unreal part sin (x / 2) * (u, v, w).

If the coordinates of the axis (u, v, w) in the original trihedron are (u, w, w), they will be (u, w, v) in your trihedron.

Thus, if the original quaternion was (a, b, c, d) - a + ib + jc + kd - the quaternion should be converted to (a, b, d, c) in your trihedron.

EDIT

But since your trihedron is left, the angle must also be canceled, so the same rotation can finally be expressed by the quaternion (a, -b, -d, -c) in your trihedron.

+12
source

This is a concise version of the answer to a slightly different question.

The problem you are asking about arises even if the two coordinate systems are the same; It turns out that coups do not make the problem much more difficult. Here's how to do it in general. To change the base of a quaternion, say, from ROS (for the right hand, Z up) to Unity (for the left hand, Y up):

 mat3x3 ros_to_unity = /* construct this by hand by mapping input axes to output axes */; mat3x3 unity_to_ros = ros_to_unity.inverse(); quat q_ros = ...; mat3x3 m_unity = ros_to_unity * mat3x3(q_ros) * unity_to_ros; quat q_unity = mat_to_quat(m_unity); 

Lines 1-4 are just the fooobar.com/questions/231456 / ... method: "How do you change the base on the matrix?"

Line 5 is interesting; not all matrices are converted to quats, but if ros_to_unity is correct, then this conversion will succeed.

Note that this will give you the correct result, but it does a great job - converting to and from the matrix, some multiplications, inversion. But you can check its results and then write a special version that swaps or flips the axes, like the one received by aka.nice.

0
source

Source: https://habr.com/ru/post/1213983/


All Articles