偏航、俯仰和滚动旋转到六个浮点变量

Yaw, pitch, and roll rotations to six float variables

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

我将如何使函数输出这些浮点数?

请求更多示例:Egor Skriptunoff

我目前的代码可以计算除第 2 和第 3 之外的所有浮点数。

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

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

-- The second float when the Yaw is 0 degrees
math.sin(math.rad(Pitch))*math.sin(math.rad(Roll))*-1

-- The second float when the Pitch is 0 degrees
math.sin(math.rad(Yaw))*math.cos(math.rad(Roll))

-- The second float when the Roll is 0 degrees
math.sin(math.rad(Yaw))*math.sin(math.rad(Pitch))

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

-- The third float when Yaw is 0 degrees
math.sin(math.rad(Pitch))*math.cos(math.rad(Roll))

-- The third float when Pitch is 0 degrees
math.sin(math.rad(Yaw))*math.sin(math.rad(Roll))

-- The third float when Roll is 0 degrees
math.cos(math.rad(Yaw))*math.sin(math.rad(Pitch))
local function Rotate(X, Y, alpha)
    local c, s = math.cos(math.rad(alpha)), math.sin(math.rad(alpha))
    local t1, t2, t3 = X[1]*s, X[2]*s, X[3]*s
    X[1], X[2], X[3] = X[1]*c+Y[1]*s, X[2]*c+Y[2]*s, X[3]*c+Y[3]*s
    Y[1], Y[2], Y[3] = Y[1]*c-t1, Y[2]*c-t2, Y[3]*c-t3
end

local function convert_rotations(Yaw, Pitch, Roll)
    local F, L, T = {1,0,0}, {0,1,0}, {0,0,1}
    Rotate(F, L, Yaw)
    Rotate(F, T, Pitch)
    Rotate(T, L, Roll)
    return {F[1], -L[1], -T[1], -F[3], L[3], T[3]}
end