Can i switch X Y Z in a quaternion?

前端 未结 4 1709
忘掉有多难
忘掉有多难 2021-02-08 14:28

i have a coordinate system where the Y axis is UP. I need to convert it to a coordinate system where Z is UP. I have the rotations stored in quaternions, so my question is : if

4条回答
  •  终归单人心
    2021-02-08 14:45

    I'm adapting my answer from this post since the one here was the older and likely more generic one.

    It's probably best to consider this in the context of how you convert angle and axis to a quaternion. In Wikipedia you can read that you describe a rotation by an angle θ around an axis with unit direction vector (x,y,z) using

    q = cos(θ/2) + sin(θ/2)(xi + yj + zk)

    Your post only tells us Y ↦ Z, i.e. the old Y direction is the new Z direction. What about the other directions? You probably want to keep X ↦ X, but that still leaves us with two alternatives.

    1. Either you use Z ↦ Y. In that case you change between left-handed and right-handed coordinate system, and the conversion is essentially a reflection.
    2. Or you use Z ↦ −Y, then it's just a 90° rotation about the X axis. The handedness of the coordinate system remains the same.

    Change of chirality

    Considering the first case first. What does changing the coordinate system do to your angle and axis? Well, the axis coordinates experience the same coordinate swapping as your points, and the angle changes its sign. So you have

    cos(−θ/2) + sin(−θ/2)(xi + zj + yk)

    Compared to the above, the real part does not change (since cos(x)=cos(−x)) but the imaginary parts change their sign, in addition to the change in order. Generalizing from this, a quaternion a + bi + cj + dk describing a rotation in the old coordinate system would be turned into a − bi − dj − ck in the new coordinate system. Or into −a + bi + dj + ck which is a different description of the same rotation (since it changes θ by 360° but θ/2 by 180°).

    Preserved chirality

    Compared to this, the second case of Z ↦ −Y maintains the sign of θ, so you only have to adjust the axis. The new Z coordinate is the old Y coordinate, and the new Y coordinate is the negated old Z coordinate. So a + bi + cj + dk gets converted to a + bi − dj + ck (or its negative). Note that this is just a multiplication of the quaternion by i or −i, depending on which side you multiply it. If you want to write this as a conjugation, you have θ=±45° so you get square roots in the quaternion that expresses the change of coordinate system.

提交回复
热议问题