【发布时间】:2011-01-01 02:28:09
【问题描述】:
我正在尝试使用 .NET/C# 将用欧拉角描述的 3D 旋转转换为矩阵,然后再返回。我的约定是:
- 左手系统(x 右,y 上,z 向前)
- 旋转顺序:围绕 y 航向,围绕 x 俯仰,围绕 z 倾斜
- 使用左手定则旋转为正数(拇指指向+无穷大)
我的试验是:
欧拉到矩阵(为了简化,我删除了 x,y,z 转换部分)
Matrix3D matrix = new Matrix3D() {
M11 = cosH * cosB - sinH * sinP * sinB,
M12 = - sinB * cosP,
M13 = sinH * cosB + cosH * sinP * sinB,
M21 = cosH * sinB + sinH * sinP * cosB,
M22 = cosB * cosP,
M23 = sinB * sinH - cosH * sinP * cosB,
M31 = - sinH * cosP,
M32 = - sinP,
M33 = cosH * cosP,
};
欧拉矩阵
const double RD_TO_DEG = 180 / Math.PI;
double h, p, b; // angles in degrees
// extract pitch
double sinP = -matrix.M23;
if (sinP >= 1) {
p = 90; } // pole
else if (sinP <= -1) {
p = -90; } // pole
else {
p = Math.Asin(sinP) * RD_TO_DEG; }
// extract heading and bank
if (sinP < -0.9999 || sinP > 0.9999) { // account for small angle errors
h = Math.Atan2(-matrix.M31, matrix.M11) * RD_TO_DEG;
b = 0; }
else {
h = Math.Atan2(matrix.M13, matrix.M33) * RD_TO_DEG;
b = Math.Atan2(matrix.M21, matrix.M22) * RD_TO_DEG; }
一定是错的。如果我取 3 个角度,将它们转换为矩阵并将矩阵转换回角度,如果结果与初始值不同。
我浏览了几个具有不同公式的网站,从 euclideanspace.com 开始,但我现在完全迷路了,找不到正确的计算方法。我很感激一点帮助。船上有数学家吗?
【问题讨论】:
-
大部分文献都会用右手坐标系和旋转角度来表达这些操作。您最好翻转一些符号以将数据放入右手系统,进行矩阵运算,然后转换回左手系统。这可能会花费一些额外的操作,但会更容易理解!
-
这是一个具有连续“关节”的系统,可以旋转以移动相机。实际上,我必须在左手系统中维护 HPB 值,因为用户必须以这种方式输入和查看。最后,我将它们转换为一个右手系统,具有不同的航向原点,以便能够使用右手的 WPF 3D 进行绘制。
标签: c# math matrix 3d euler-angles