function getEulerFromQuaternion5( tQuaternion )
local x, y, z = 0, 0, 0
local qx = tQuaternion[1]
local qy = tQuaternion[2]
local qz = tQuaternion[3]
local qw = tQuaternion[4]
local sqw = qw * qw
local sqx = qx * qx
local sqy = qy * qy
local sqz = qz * qz
local unit = sqx + sqy + sqz + sqw
local test = qx * qw - qy * qz
if test > 0.4999999 * unit then
x = math.pi / 2
y = 2.0 * math.atan2( qy, qw )
z = 0
elseif test < -0.4999999 * unit then
x = -( math.pi / 2 )
y = 2.0 * math.atan2( qy, qw )
z = 0
else
x = math.asin( 2 * test )
y = math.atan2( 2 * ( qx * qz + qy * qw ), 1 - 2 * ( sqy + sqx ) )
z = math.atan2( 2 * ( qx * qy + qz * qw ), 1 - 2 * ( sqx + sqz ) )
end
return math.deg( x ), math.deg( y ), math.deg( z )
end
print( getEulerFromQuaternion5( { 0, 0, -0.7398733497, 0.6727461815 } ) )
В некоторых случаях надо использовать math.abs и прибавлять 180.