欧拉转换为基质,基质欧拉 [英] Conversion euler to matrix and matrix to euler
问题描述
我想转换欧拉角度来看描述成一个矩阵3D旋转,然后回来,用.NET / C#。我的约定是:
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.com,但我现在已经完全丧失,无法找到合适的计算。我AP preciate一点帮助。是否有一个数学家板载?
I have browsed several sites with different formulas, starting with euclideanspace.com, 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
编辑:完整的解决方案如下
Full solution follows
我的推导:
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 |
乘以您的订购:
Multiplied with your ordering:
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 |
这给出了相反的推导:
Which gives reverse derivations:
谭B = M12 / M22
tan B = M12/M22
罪P = -m32
谭H = M31 / M33
tan H = M31/M33
这篇关于欧拉转换为基质,基质欧拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!