Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

c# - Switch chirality of a quaternion in code?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...