偏航、俯仰和横滚旋转将传递到六个浮点变量中。

我需要帮助创建一个函数,将三个角度(以度为单位,偏航俯仰和横滚)转换为六个浮点变量。

如何制作一个函数来输出这些浮点数?

  • {0, 0, 0} = {1, 0, 0, -0, -0, 1}
  • {45, 0, 0} = {0.70710676908493, 0.70710676908493, 0, -0, -0, 1}
  • {0, 90, 0} = {-4.3711388286738e-08, 0, 1, -1, 0, -4.3711388286738e-08}
  • {0, 0, 135} = {1, -0, 0, -0, -0.70710676908493, -0.70710676908493}
  • {180, 180, 0} = {1, -8.7422776573476e-08, 8.7422776573476e-08, 8.7422776573476e-08, 0, -1}
  • {225, 0, 225} = {-0.70710682868958, 0.5, 0.5, -0, 0.70710670948029, -0.70710682868958}
  • {270, 270, 270} = {1.4220277639103e-16, -2.3849761277006e-08, 1, 1, 1.1924880638503e-08, 1.42202776319103e-16}
  • {315, 315, 315} = {0.5, -0.85355341434479, 0.14644680917263, 0.70710688829422, 0.5, 0.5}

由 Egor Skriptunoff 要求更多示例

  • {10, 20, 30} = {0.92541658878326, -0.018028322607279, 0.37852230668068, -0.34202012419701, -0.46984630823135, 0.81379765272141}
  • {10, 30, 20} = {0.85286849737167, -0.0052361427806318, 0.52209949493408, -0.5, -0.29619812965393, 0.81379765272141}
  • {20, 10, 30} = {0.92541658878326, 0.21461015939713, 0.3123245537281, -0.17364817857742, -0.49240386486053, 0.85286849737167}
  • {20, 30, 10} = {0.81379765272141, 0.25523611903191, 0.52209949493408, -0.5, -0.15038372576237, 0.85286849737167}
  • {30, 10, 20} = {0.85286849737167, 0.41841205954552, 0.3123245537281, -0.17364817857742, -0.33682405948639, 0.92541658878326}
  • {30, 20, 10} = {0.81379765272141, 0.4409696161747, 0.37852230668068, -0.34202012419701, -0.16317591071129, 0.92541658878326}

我目前拥有的代码可以计算除第二和第三个浮点数之外的所有浮点数。

function convert_rotations(Yaw, Pitch, Roll)
    return {
        math.cos(math.rad(Yaw))*math.cos(math.rad(Pitch)),
        0,
        0,
        math.sin(math.rad(Pitch))*-1,
        math.sin(math.rad(Roll))*math.cos(math.rad(Pitch))*-1,
        math.cos(math.rad(Roll))*math.cos(math.rad(Pitch))
    }
end

我似乎找不到所有角度都非零的第二个浮点数和第三个浮点数的正确数学方法,但我想出了这个:

-- 当偏航角是0度时的第二个浮点数
math.sin(math.rad(Pitch))*math.sin(math.rad(Roll))*-1

-- 当俯仰角是0度时的第二个浮点数
math.sin(math.rad(Yaw))*math.cos(math.rad(Roll))

-- 当横滚角为0度时的第二个浮点数
math.sin(math.rad(Yaw))*math.sin(math.rad(Pitch))

至于第三个浮点数,我想出了这个:

-- 当偏航角为0度时的第三个浮点数
math.sin(math.rad(Pitch))*math.cos(math.rad(Roll))

-- 当俯仰角为0度时的第三个浮点数
math.sin(math.rad(Yaw))*math.sin(math.rad(Roll))

-- 当横滚角为0度时的第三个浮点数
math.cos(math.rad(Yaw))*math.sin(math.rad(Pitch))
点赞
用户1847592
用户1847592

``` 本地函数 Rotate(X, Y, alpha) 的作用是将向量 X 沿着向量 Y 平面内绕着 alpha 角度旋转。其中用到了三角函数 cos()sin(),并且将角度 alpha 转化成弧度。

在函数 convert_rotations(Yaw, Pitch, Roll) 中,先初始化了三个向量 FLT,分别表示前方向、左方向和上方向。然后依次对这三个向量做 Yaw、Pitch 和 Roll 的旋转变换,最后返回一个包含计算结果的表格 {F[1], -L[1], -T[1], -F[3], L[3], T[3]}

2015-05-30 06:37:24