Geodesics on an ellipsoid in MoonBit (distance, direct and inverse problems, areas), a port of geographiclib-geodesic 2.2.0
moon add t-ujiie-g/geodesic/// The distance in meters from Tokyo to Paris, and the point a quarter of the way.
fn tokyo_paris() -> (Double, (Double, Double)) {
let g = @geodesic.Geodesic::wgs84()
let line = g.inverse_line(35.6812, 139.7671, 48.8566, 2.3522)
let p = line.position(false, line.s13 / 4.0)
(line.s13, (p.lat2, p.lon2))
}
///|
/// The area in square meters of a ring given as lng, lat pairs.
fn ring_area(coords : Array[Double]) -> Double {
@geodesic.Geodesic::wgs84().measure_path(coords[:], true)[1]
}pub struct Geodesic {
a : Double
f : Double
// private fields
}fn Geodesic::inverse_line(self : Geodesic, lat1 : Double, lon1 : Double, lat2 : Double, lon2 : Double) -> GeodesicLinepub struct GeodesicLine {
lat1 : Double
lon1 : Double
azi1 : Double
s13 : Double
a13 : Double
// private fields
}fn GeodesicLine::position(self : GeodesicLine, arcmode : Bool, s12_a12 : Double, unroll? : Bool) -> Positionpub(all) struct Inverse {
s12 : Double
azi1 : Double
azi2 : Double
a12 : Double
area : Double
}pub struct PolygonArea {
polyline : Bool
// private fields
}pub(all) struct Position {
lat2 : Double
lon2 : Double
azi2 : Double
s12 : Double
a12 : Double
}Install
Download zipGeodesics on an ellipsoid in MoonBit (distance, direct and inverse problems, areas), a port of geographiclib-geodesic 2.2.0