Does anyone know about some geography library in Monkey C? Things like: distance between two locations, distance between a line segment (given as 2 locations) and a location, etc.
Does anyone know about some geography library in Monkey C? Things like: distance between two locations, distance between a line segment (given as 2 locations) and a location, etc.
I don't know of any library like that, but here's a solution for the distance between two locations, if you need it:
For folks looking for general geography utils, i.e. the stuff that is available in most languages through packages like GDAL, I've recently open-sourced a small amount of code in the form of a library: https://github.com/bostonrwalker/navutils/blob/main/source/navutils.mc
Collaborators are welcome!
Calculate initial bearing with
θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
Where:
Δλ
is the difference in longitude (λ2 - λ1).dxt = asin( sin(δ13) ⋅ sin(θ13−θ12) ) ⋅ R
dxt
is the cross-track distance. δ13
is the angular distance from the start point to the third point (the point in question).θ13
is the initial bearing from the start point to the third point.θ12
is the initial bearing from the start point to the end point of the segment.R
is the Earth's radius.If you’ve got the Haversine distance, divide by the Earths radius to get angular distance.
All in radians.