如何将四元数转换为角度?
How can I convert a Quaternion to an angle?
我正在尝试使用 https://docs.microsoft.com/en-us/xamarin/essentials/orientation-sensor 上的这个库来计算设备的俯仰、偏航和滚动。图书馆工作,并且 returns 在四元数中。
我希望能够将这个四元数转换为 360 度的俯仰、偏航和滚动 space,以及设备旋转距离的百分比,从 0 到 100 "towards" 360.
我一直在研究这个,并找到了各种数学方程式,用数学符号表示,如何实现这样的事情。这些文档还讨论了诸如欧拉角、弧度和其他各种我没有任何概念的概念。
C# 中有没有一种方法可以将四元数转换为 a) 360 度角 space 和 b) 设备在特定轴上旋转的 0-100 百分比?
谢谢!
根据 document:
A Quaternion value is very closely related to rotation around an axis.
If an axis of rotation is the normalized vector (ax, ay, az), and the
rotation angle is Θ, then the (X, Y, Z, W) components of the
quaternion are:
(ax·sin(Θ/2), ay·sin(Θ/2), az·sin(Θ/2), cos(Θ/2))
首先,从W
得到Θ
:
var Θ = Math.Acos(W)*2;
然后,得到ax
、ay
、az
:
var ax = X / Math.Sin(Math.Acos(Θ));
var ay = Y / Math.Sin(Math.Acos(Θ));
var az = Z / Math.Sin(Math.Acos(Θ));
四元数的轴角为[ax,ay,az]。
例如,[0,0,0.7071068,0.7071068]
的 Quaternion
将具有 [0,0,1]
的 Axis-Angle
。你可以认为它在 Z 轴上旋转了 90 度。
我正在尝试使用 https://docs.microsoft.com/en-us/xamarin/essentials/orientation-sensor 上的这个库来计算设备的俯仰、偏航和滚动。图书馆工作,并且 returns 在四元数中。
我希望能够将这个四元数转换为 360 度的俯仰、偏航和滚动 space,以及设备旋转距离的百分比,从 0 到 100 "towards" 360.
我一直在研究这个,并找到了各种数学方程式,用数学符号表示,如何实现这样的事情。这些文档还讨论了诸如欧拉角、弧度和其他各种我没有任何概念的概念。
C# 中有没有一种方法可以将四元数转换为 a) 360 度角 space 和 b) 设备在特定轴上旋转的 0-100 百分比?
谢谢!
根据 document:
A Quaternion value is very closely related to rotation around an axis. If an axis of rotation is the normalized vector (ax, ay, az), and the rotation angle is Θ, then the (X, Y, Z, W) components of the quaternion are:
(ax·sin(Θ/2), ay·sin(Θ/2), az·sin(Θ/2), cos(Θ/2))
首先,从W
得到Θ
:
var Θ = Math.Acos(W)*2;
然后,得到ax
、ay
、az
:
var ax = X / Math.Sin(Math.Acos(Θ));
var ay = Y / Math.Sin(Math.Acos(Θ));
var az = Z / Math.Sin(Math.Acos(Θ));
四元数的轴角为[ax,ay,az]。
例如,[0,0,0.7071068,0.7071068]
的 Quaternion
将具有 [0,0,1]
的 Axis-Angle
。你可以认为它在 Z 轴上旋转了 90 度。