mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Add vector.axis_angle3
This commit is contained in:
parent
c14c208a61
commit
f3d856c2db
13
vector.lua
13
vector.lua
@ -194,6 +194,19 @@ function angle(v, w)
|
|||||||
return math.acos(dot(v, w) / length(v) / length(w))
|
return math.acos(dot(v, w) / length(v) / length(w))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- See https://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToAngle/
|
||||||
|
function axis_angle3(euler_rotation)
|
||||||
|
assert(#euler_rotation == 3)
|
||||||
|
euler_rotation = divide_scalar(euler_rotation, 2)
|
||||||
|
local cos = apply(euler_rotation, math.cos)
|
||||||
|
local sin = apply(euler_rotation, math.sin)
|
||||||
|
return normalize_zero{
|
||||||
|
sin[1] * sin[2] * cos[3] + cos[1] * cos[2] * sin[3],
|
||||||
|
sin[1] * cos[2] * cos[3] + cos[1] * sin[2] * sin[3],
|
||||||
|
cos[1] * sin[2] * cos[3] - sin[1] * cos[2] * sin[3],
|
||||||
|
}, 2 * math.acos(cos[1] * cos[2] * cos[3] - sin[1] * sin[2] * sin[3])
|
||||||
|
end
|
||||||
|
|
||||||
-- Uses Rodrigues' rotation formula
|
-- Uses Rodrigues' rotation formula
|
||||||
-- axis must be normalized
|
-- axis must be normalized
|
||||||
function rotate3(v, axis, angle)
|
function rotate3(v, axis, angle)
|
||||||
|
Loading…
Reference in New Issue
Block a user