Fix vector.rotate3

This commit is contained in:
Lars Mueller 2022-01-11 18:02:39 +01:00
parent bcda0511b1
commit 228bfda006

@ -190,10 +190,13 @@ function angle(v, w)
end
-- Uses Rodrigues' rotation formula
-- axis must be normalized
function rotate3(v, axis, angle)
assert(#v == 3 and #axis == 3)
local cos = math.cos(angle)
return multiply_scalar(v, cos)
+ multiply_scalar(cross3(axis, v), math.sin(angle))
-- Minetest's coordinate system is *left-handed*, so `v` and `axis` must be swapped here
+ multiply_scalar(cross3(v, axis), math.sin(angle))
+ multiply_scalar(axis, dot(axis, v) * (1 - cos))
end