【问题标题】:Retrieve 3 Euler angles from 2 Vector3D从 2 个 Vector3D 中检索 3 个欧拉角
【发布时间】:2013-03-25 15:10:25
【问题描述】:

如何从 2 vector3D 中检索 3 个欧拉角?

谢谢

切德雷

dim vector1 = new Vector3D(0, 0, 1);

dim vector2 = new Vector3D(0.33, 0.45, 0.49);


dim myEuler = GetEulerFrom2Vector(vector1,vector2); // ?????

我在直角坐标系中工作,我使用 ZYX 欧拉约定

【问题讨论】:

    标签: c# .net vb.net robotics


    【解决方案1】:

    我们可以假设这两个向量相互垂直vector1.Dot(vector2)==0吗?如果是则找到第三个向量组成一个坐标系

    vector1 = vector1.Normalized();
    vector2 = vector2.Normalized();
    vector3 = VectorCross(vector1,vector2).Normalized();
    

    其中VectorCross 是 3D 向量叉积,Normalized() 返回单位向量。

    现在你的旋转矩阵E

     | vector1.x   vector2.x   vector3.x |
     | vector1.y   vector2.y   vector3.y |
     | vector1.z   vector2.z   vector3.z |
    

    现在您可以使用instructions here 从旋转矩阵转到欧拉角。

    PS。如果vector2vector1 不垂直,则可以在计算vector3 后使其垂直于vector2 = CrossProduct(vector3, vector1).Normalized()

    这是我用来从两个轴转到旋转矩阵的代码:

        public static mat3 AlignZX(vec3 unit_z, vec3 unit_x)
        {
            unit_x=unit_x.Normalized();
            unit_z=unit_z.Normalized();
            vec3 unit_y=unit_z.Cross(unit_x);
            unit_x=unit_y.Cross(unit_z);
            return mat3.Combine(unit_x, unit_y, unit_z);
        }
        public static mat3 AlignXY(vec3 unit_x, vec3 unit_y)
        {
            unit_x=unit_x.Normalized();
            unit_y=unit_y.Normalized();
            vec3 unit_z=unit_x.Cross(unit_y);
            unit_y=unit_z.Cross(unit_x);
            return mat3.Combine(unit_x, unit_y, unit_z);
        }
        public static mat3 AlignYZ(vec3 unit_y, vec3 unit_z)
        {
            unit_y=unit_y.Normalized();
            unit_z=unit_z.Normalized();
            vec3 unit_x=unit_y.Cross(unit_z);
            unit_z=unit_x.Cross(unit_y);
            return mat3.Combine(unit_x, unit_y, unit_z);
        }
    

    【讨论】:

      【解决方案2】:

      我使用旋转矩阵:

      R11 R12 R13
      R21 R22 R23
      R31 R32 R33
      

      R = Rz Ry Rx

      if (R31 <> ±1)
          y1 = -sin-1(R31)
          y2 = pi + sin-1(R31)
      
          x1 = atan2 (R32/cos y1,R33/cos y1)
          x2 = atan2 (R32/cos y2,R33/cos y2)
      
          z1 = atan2( R21/cos y1,R11/cos y1)
          z2 = atan2( R21/cos y2,R11/cos y2)
              Else
          z= anything; can set to 0
          if (R31 = -1)
              y = -pi / 2
              x = z  + atan2(R12,R13)
           Else
               y = -pi / 2
               x  = -z + atan2(-R12,-R13)     
          End If
      End If
      

      https://truesculpt.googlecode.com/hg-history/38000e9dfece971460473d5788c235fbbe82f31b/Doc/rotation_matrix_to_euler.pdf

      或者简单的版本

          result.X = Math.Atan2(R32, R33) * (180.0 / Math.PI)
          result.Y = Math.Atan2(-1 * R31, Math.Sqrt(R32 * R32 + R33 * R33)) * (180.0 / Math.PI)
          result.Z = Math.Atan2(R21, R11) * (180.0 / Math.PI)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-23
        • 1970-01-01
        • 1970-01-01
        • 2019-10-27
        • 2013-08-28
        • 1970-01-01
        相关资源
        最近更新 更多