在代码中切换四元数的手征性? [英] Switch chirality of a quaternion in code?

查看:82
本文介绍了在代码中切换四元数的手征性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四元数数据,我试图将其从右手的Y向上坐标空间切换到左手的Z向上坐标空间.通过阅读此书,我需要做的是switch the chirality.

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

我不能把头缠住它.

说我的四元数为:

public static float[] quat= new float[4](0.70711,0.70711,0,0);

在C#代码中,如何切换手性?

In c# code, how do i switch the chirality?

我尝试取反该轴,并简单地交换ZY值.正如该链接中所建议的,我尝试将四元数乘以另一个等于90度的四元数.仍然看到错误的旋转.

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.

谢谢.

推荐答案

假定原始坐标系A对摄像机具有X向右,Y向上,Z.新坐标系B的X向右,相机Y,Z向上.因此,本质上您需要交换Y和Z轴.到目前为止正确吗?并且您有一个四元数 q 描述了系统A中的一些旋转.您想找到一个四元数 r 描述了系统B中的相同旋转.

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.

最好将角度和轴转换为四元数时考虑这一点.在维基百科中,您可以了解到,您描述了围绕具有单位方向矢量的轴以角度θ旋转. (x,y,z)使用

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)

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)

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

与上述相比,实部不变(因为cos( x )= cos(- x )),但是虚部改变了其符号除了更改顺序.概括地说,在旧坐标系中描述旋转的四元数a + bi + cj + dk在新坐标系中将变成a - bi - dj - ck.

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.

这篇关于在代码中切换四元数的手征性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆