问题
I have quaternion data that I am trying to switch from a right-handed Y-up coordinate space, to a left-handed Z-up coordinate space. From reading up on this, what I need to do is switch the chirality
.
The only info i can find is this
And i cannot wrap my head around it.
Say that I have my Quaternion as:
public static float[] quat= new float[4](0.70711,0.70711,0,0);
In c# code, how do i switch the chirality?
I have tried negating the axis, and simply swapping the Z
and Y
values. I have tried multiplying the quaternion by a another quaternion equaling 90 degrees, as suggested in that link. and still see incorrect rotations.
Thank you.
回答1:
Assuming that your original coordinate system A has X right, Y up, Z to the camera. The new coordinate system B has X right, Y to the camera and Z up. So essentially you need to exchange the Y and Z axes. Right so far? And you have a quaternion q which describes some rotation in system A. You want to find a quaternion r which describes the same rotation in system B.
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)
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.
来源:https://stackoverflow.com/questions/39098154/switch-chirality-of-a-quaternion-in-code