クォータニオンからオイラー角への変換 (lua)
追記: rad_to_deg関数を書いてないけどそれは置いといて、どうもこれだとうまくいかないらしい
code:quaternion_to_euler.lua
-- クォータニオンからオイラー角への変換
local function quaternion_to_euler (q)
local roll = math.atan2(2 * (q.x * q.y + q.z * q.w), 1 - 2 * (q.y * q.y + q.z * q.z))
local sinp = 2 * (q.x * q.z - q.w - q.y)
local pitch = 0
if sinp <= -1 then
pitch = -math.pi / 2
elseif 1 <= sinp then
pitch = math.pi / 2
else
pitch = math.asin(sinp)
end
local yaw = math.atan2(2 * (q.x * q.w + q.y * q.z), 1 - 2 * (q.z * q.z + q.w * q.w))
return vector.new(math.deg(pitch), rad_to_deg(yaw), rad_to_deg(roll))
end
quaternionライブラリにオイラー角への変換がなかったので代替に
テストはしてないので使用は自己責任で
間違ってたら直しておいて♡