Module:Sandbox/trappist the monk/bearing explained

--

require ('strict');

local function bearing (from_lat, from_long, to_lat, to_long) local from_lat_rad = math.rad (from_lat); -- convert degree inputs to radians local from_long_rad = math.rad (from_long); local to_lat_rad = math.rad (to_lat); local to_long_rad = math.rad (to_long); local delta_long_rad = to_long_rad - from_long_rad; local x = math.cos (to_lat_rad) * math.sin (delta_long_rad); local y = (math.cos (from_lat_rad) * math.sin (to_lat_rad)) - (math.sin (from_lat_rad) * math.cos (to_lat_rad) * math.cos (delta_long_rad)); local beta = math.atan2 (x, y); -- result in radians beta = math.deg (beta); -- convert to degrees return (0.0 > beta) and (beta + 360.0) or beta; -- when beta is negative, add 360 degrees to make a positive bearingend

----------------------------< E X P O R T S >----------------------------------------------------------------

return