<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Ftrappist_the_monk%2Fbearing</id>
	<title>Module:Sandbox/trappist the monk/bearing - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Ftrappist_the_monk%2Fbearing"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/bearing&amp;action=history"/>
	<updated>2026-04-22T00:29:10Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/bearing&amp;diff=146604&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/bearing&amp;diff=146604&amp;oldid=prev"/>
		<updated>2022-10-23T21:01:45Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/research/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&amp;quot; )&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[--------------------------&amp;lt; B E A R I N G &amp;gt;----------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
calculates the bearing from &amp;lt;from_lat&amp;gt;/&amp;lt;from_long&amp;gt; to &amp;lt;to_lat&amp;gt;/&amp;lt;to_long&amp;gt; using the equation from&lt;br /&gt;
https://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/&lt;br /&gt;
&lt;br /&gt;
written as a response to [ [User_talk:Trappist_the_monk#Hello,_bearings] ]&lt;br /&gt;
&lt;br /&gt;
inputs in decimal degrees (degrees minutes seconds coordinates must be pre-converted)&lt;br /&gt;
	&amp;lt;from_lat&amp;gt; – latitude (north +, south -) of the starting point&lt;br /&gt;
	&amp;lt;from_long&amp;gt; – longitude (east +, west -) of the starting point&lt;br /&gt;
	&amp;lt;to_lat&amp;gt; – latitude (north +, south -) of the ending point&lt;br /&gt;
	&amp;lt;to_long&amp;gt; – longitude (east +, west -) of the ending point&lt;br /&gt;
&lt;br /&gt;
returns bearing from &amp;#039;from&amp;#039; to &amp;#039;to&amp;#039; in decimal degrees&lt;br /&gt;
&lt;br /&gt;
This code only works from the debug console:&lt;br /&gt;
	=p.bearing (39.099912, -94.581213, 38.627089, -90.200203)					-- original worked example St Louis, Missouri bears 96.5° from Kansas City, Kansas&lt;br /&gt;
	=p.bearing (38.627089, -90.200203, 39.099912, -94.581213)					-- reversed example: Kansas City, Kansas bears 279.3° from St Louis, Missouri&lt;br /&gt;
&lt;br /&gt;
for negative lat/long (south/west) do not use U+2212 minus sign; use keyboard U+002D hyphen-minus &lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
require (&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
local function bearing (from_lat, from_long, to_lat, to_long)&lt;br /&gt;
	local from_lat_rad = math.rad (from_lat);									-- convert degree inputs to radians&lt;br /&gt;
	local from_long_rad = math.rad (from_long);&lt;br /&gt;
	local to_lat_rad = math.rad (to_lat);&lt;br /&gt;
	local to_long_rad = math.rad (to_long);&lt;br /&gt;
	&lt;br /&gt;
	local delta_long_rad = to_long_rad - from_long_rad;&lt;br /&gt;
	local x = math.cos (to_lat_rad) * math.sin (delta_long_rad);&lt;br /&gt;
	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));&lt;br /&gt;
	local beta = math.atan2 (x, y);												-- result in radians&lt;br /&gt;
	beta = math.deg (beta);														-- convert to degrees&lt;br /&gt;
	return (0.0 &amp;gt; beta) and (beta + 360.0) or beta;								-- when beta is negative, add 360 degrees to make a positive bearing&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T S &amp;gt;----------------------------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	bearing = bearing,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>