欧拉到矩阵和矩阵到欧拉的转换

编程入门 行业动态 更新时间:2024-10-19 21:19:49
本文介绍了欧拉到矩阵和矩阵到欧拉的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 .NET/C# 将根据欧拉角描述的 3D 旋转转换为矩阵,然后返回.我的约定是:

I'm trying to convert a 3D rotation described in term of euler angles into a matrix and then back, using .NET/C#. My conventions are:

  • 左手系统(x 右,y 上,z 向前)
  • 旋转顺序:绕y,绕x俯仰,绕z倾斜
  • 使用左手规则(拇指指向+无穷大)为正旋转

我的试用期是:

欧拉转矩阵(为了简化,我删除了 x,y,z 平移部分)

Euler to matrix (I've removed the x,y,z translation part for simplification)

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 个角度,将它们转换为矩阵并将矩阵转换回角度,结果与初始值不同.

It must be wrong. If I take 3 angles, convert them into a matrix and convert the matrix back into angles, the result if different than the intial values.

我浏览了几个具有不同公式的站点,从 euclideanspace 开始,但我现在完全迷失了,找不到正确的计算.我很感激一点帮助.机上有数学家吗?

I have browsed several sites with different formulas, starting with euclideanspace, but I'm now completely lost, and can't find the right computations. I' appreciate a little help. Is there a mathematician onboard?

推荐答案

首先,应该:

sinP = -matrix.M32

完整的解决方案如下

我的推导:

Rx(P)=| 1 0 0 | | 0 cos P -sin P | | 0 sin P cos P | Ry(H)=| cos H 0 sin H | | 0 1 0 | | -sin H 0 cos H | Rz(B)=| cos B -sin B 0 | | sin B cos B 0 | | 0 0 1 |

乘以您的订单:

R = Ry(H)*Rx(P)*Rz(B) = | cos H*cos B+sin H*sin P*sin B cos B*sin H*sin P-sin B*cos H cos P*sin H | | cos P*sin B cos B*cos P -sin P | | sin B*cos H*sin P-sin H*cos B sin H*sin B+cos B*cos H*sin P cos P*cos H |

给出反向推导:

tan B = M12/M22

tan B = M12/M22

sin P = -M32

sin P = -M32

棕褐色 H = M31/M33

tan H = M31/M33

更多推荐

欧拉到矩阵和矩阵到欧拉的转换

本文发布于:2023-11-29 20:42:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647574.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矩阵   欧拉

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!