[added] mathx.lerp_angle and notes about possible changes to mathx.relative_angle

This commit is contained in:
Max Cahill 2020-04-30 16:38:59 +10:00
parent e75147ec77
commit 7deef92639

View File

@ -175,10 +175,19 @@ end
mathx.normalize_angle = mathx.normalise_angle
--get the relative turn between two angles
function mathx.relative_angle(a1, a2)
a1 = mathx.normalise_angle(a1)
a2 = mathx.normalise_angle(a2)
return mathx.normalise_angle(a1 - a2)
--note: cam considering reversing this, as the (b - a) version is more useful and intuitive...
function mathx.relative_angle(a, b)
a = mathx.normalise_angle(a)
b = mathx.normalise_angle(b)
return mathx.normalise_angle(a - b)
end
--lerp between two angles
function mathx.lerp_angle(a, b, t)
--(note: if we change relative_angle this will need changing,
-- it's a good example of why relative_angle should probably change)
local dif = mathx.relative_angle(a, b)
return mathx.normalise_angle(a - dif * t)
end
--geometric rotation with multi-return