RosettaCodeData/Task/Angle-difference-between-two-bearings/Pluto/angle-difference-between-two-bearings.pluto
2026-04-30 12:34:36 -04:00

31 lines
753 B
Text

require "math2"
local function subtract(b1, b2)
local d = (b2 - b1) % 360
if d < -180 then d += 360 end
if d >= 180 then d -= 360 end
return math.toplaces(d, 4)
end
local pairs = {
{ 20, 45},
{-45, 45},
{-85, 90},
{-95, 90},
{-45, 125},
{-45, 145},
{ 29.4803, -88.6381},
{-78.3251, -159.036},
{-70099.74233810938, 29840.67437876723},
{-165313.6666297357, 33693.9894517456},
{1174.8380510598456, -154146.66490124757},
{60175.77306795546, 42213.07192354373}
}
print("Differences (to 4dp) between these bearings:")
for pairs as pair do
local [p1, p2] = pair
local diff = subtract(p1, p2)
local offset = p1 < 0 ? " " : " "
print($"{offset}{p1} and {p2} -> {diff}")
end