2

我正在使用 Catia 软件。当我在我的 CAD 绘图中查询对象的位置时,系统返回一个 3x4 矩阵

[轮换 | 翻译]

我认为旋转以 ZXZ 方式表示,但为了进一步处理,我想将该旋转矩阵转换为 XYZ 表示法,这是可行的吗?

编辑:

我的对象位于 [ 0, 0, 1000 ] Catia 给出的方向是

R = [ 1  0  0 ]  
    [ 0  0  1 ]  
    [ 0 -1  0 ]

当我尝试将自己的点 [0, 0, 50] 相乘时(只是 Z 轴上的偏移量)

P1 = [ 0  ]
     [ 0  ]
     [ 50 ]

R*P1 = [ 0  ]
       [ 50 ]
       [ 0  ]

这就是让我相信旋转矩阵不是右手符号的 XYZ 的原因。

4

4 回答 4

1

我刚刚测试了这段代码,它工作正常。它遍历所有角度的备选方案并返回最接近 0 的备选方案。

public class Matrix3
{
    double a11,a13,a13,a21,a22,a23,a31,a32,a33;

    public void GetEulerZXZDegree(out double a, out double b, out double c)
    {
        GetEulerZXZ(out a, out b, out c);
        a*=180/Math.PI;
        b*=180/Math.PI;
        c*=180/Math.PI;
    }
    public void GetEulerZXZ(out double a, out double b, out double c)
    {
        // Options
        double[] a_list=new double[] { Math.Atan2(-a13, a23), Math.Atan2(a13, -a23) };
        double[] c_list=new double[] { Math.Atan2(a31, a32), Math.Atan2(-a31, -a32) };
        double[] b_list=new double[] { Math.PI/2-Math.Asin(a33), -Math.PI/2+Math.Asin(a33) };

        int min_a_index=FindMinAbsIndex(a_list);
        int min_b_index=FindMinAbsIndex(b_list);
        int min_c_index=FindMinAbsIndex(c_list);

        a=a_list[min_a_index];
        b=b_list[min_b_index];
        c=c_list[min_c_index];
    }
    public void GetEulerZYXDegree(out double a, out double b, out double c)
    {
        GetEulerZYX(out a, out b, out c);
        a*=180/Math.PI;
        b*=180/Math.PI;
        c*=180/Math.PI;
    }
    public void GetEulerZYX(out double a, out double b, out double c)
    {
        // Options
        double[] a_list=new double[] { Math.Atan2(a21, a11), Math.Atan2(-a21, -a11) };
        double[] c_list=new double[] { Math.Atan2(a32, a33), Math.Atan2(-a32, -a33) };
        double[] b_list=new double[] { -Math.Asin(a31), Math.Asin(a31)-Math.PI };

        int min_a_index=FindMinAbsIndex(a_list);
        int min_b_index=FindMinAbsIndex(b_list);
        int min_c_index=FindMinAbsIndex(c_list);

        a=a_list[min_a_index];
        b=b_list[min_b_index];
        c=c_list[min_c_index];
    }

    // This returns the index of the smallest number
    public static int FindMinAbsIndex(double[] list)
    {
        if(list.Length==0) return -1;
        double x=Math.Abs(list[0]);
        int index=0;
        for(int i=1; i<list.Length; i++)
        {
            if(Math.Abs(list[i])<x)
            {
                index=i;
                x=Math.Abs(list[i]);
            }
        }
        return index;
    }
}

这是一个单元测试:

    /// <summary>
    ///A test for GetEulerZXZDegree
    ///</summary>
    [TestMethod()]
    public void GetEulerZXZDegreeTest()
    {
        // Make matrix from three rotations
        // RZ(75)*RX(22)*RZ(-12)
        Matrix3 target = 
            Rotations.RotateZDegrees( 75)*
            Rotations.RotateXDegrees( 22)*
            Rotations.RotateZDegrees(-12);
        //Matrix3 target=new Matrix3(
        //    0.439367031912771, -0.822208517146682, 0.361842183278486,
        //    0.894924870582839, 0.435556129311581, -0.0969553207969503,
        //    -0.0778850902285301, 0.366420540568700, 0.927183854566759);
        double a;
        double aExpected=75;
        double b;
        double bExpected=22;
        double c;
        double cExpected=-12;
        target.GetEulerZXZDegree(out a, out b, out c);
        Assert.AreEqual(aExpected, a, 1e-8);
        Assert.AreEqual(bExpected, b, 1e-8);
        Assert.AreEqual(cExpected, c, 1e-8);
    }
于 2013-02-05T20:27:50.740 回答
0

Who gives matrices in ZXZ notation? Are you sure it is the format?

If it's a regular roation matrix, then you should start by taking a unit vector along one of the axes and see where the transformation brings it. It will give you two of the euler angles. To get the third, you need to consider a plane generated by two vectors.

于 2010-06-23T19:48:28.640 回答
0

恐怕你得算算了

于 2010-06-23T18:43:24.623 回答
0

您可能会将 3x4 变换矩阵视为一组三个单位向量,它们定义变换后的坐标系轴(矩阵的前三列)和该坐标系的原点(第四列)。对于您的情况,单位向量是: 因此,在您转换后的系统中,X 轴与原始轴相同,Y 变为 -Z,Z 变为 +Y。这实际上是围绕 X 轴旋转 90 度(当 Z 转向 Y 时)。
X = (1, 0, 0)
Y = (0, 0, -1)
Z = (0, 1, 0)

于 2010-06-24T20:41:50.213 回答