geographiclib

Struct Geodesic

Source
#[repr(C)]
pub struct Geodesic { /* private fields */ }
Expand description

Ellipsoid on which Geodesic Calculations are computed

Implementations§

Source§

impl Geodesic

Source

pub fn wgs84() -> Self

Create a new WGS84 Ellipsoid

  • Semi-major Axis: 6_378_137.0
  • Flattening: 1.0/298.257_223_563
Source

pub fn ellipsoid(name: Ellipsoid) -> Self

Create a new Ellipsoid from currently existing versions

For a complete list see the Ellipsoid enum

Source

pub fn new(a: f64, f: f64) -> Self

Create new Ellipsoid with semi-major axis a in meters and a flattening f

Most users will likely want either wgs84 or ellipsoid for well defined and recongized Ellipsoids

use geographiclib::Geodesic;
let g = Geodesic::new(6_378_145.0, 1.0/298.25);
println!("{}", g);
// Geodesic { a: 6378145, f: 0.003352891869237217 }
Source

pub fn inverse( &self, lat1: f64, lon1: f64, lat2: f64, lon2: f64, ) -> (f64, f64, f64, f64)

Compute distance and azimuth from (lat1,lon1) to (lat2,lon2)

§Arguments
  • lat1: Latitude of 1st point [degrees] [-90., 90.]
  • lon1: Longitude of 1st point [degrees] [-180., 180.]
  • lat2: Latitude of 2nd point [degrees] [-90. 90]
  • lon2: Longitude of 2nd point [degrees] [-180., 180.]
§Returns
  • a12 - Distance from 1st to 2nd point [degrees]
  • s12 - Distance from 1st to 2nd point [degrees]
  • azi1 - Azimuth at 1st point [degrees]
  • azi2 - Azimuth at 2nd point [degrees]

If either point is at a pole, the azimuth is defined by keeping the longitude fixed, writing lat = ±(90° − ε), and taking the limit ε → 0+.

The solution to the inverse problem is found using Newton’s method. If this fails to converge (this is very unlikely in geodetic applications but does occur for very eccentric ellipsoids), then the bisection method is used to refine the solution.

// Example, determine the distance between JFK and Singapore Changi Airport:
use geographiclib::Geodesic;
let g = Geodesic::wgs84();
let (jfk_lat, jfk_lon) = (40.64, -73.78);
let (sin_lat, sin_lon) = (1.36, 103.99);
let (d, m, a1, a2) = g.inverse(jfk_lat, jfk_lon, sin_lat, sin_lon);
assert_eq!(d,  138.0511907301622);  // Distance degrees
assert_eq!(m,  15347512.94051294);  // Distance meters
assert_eq!(a1, 3.3057734780176125); // Azimuth at 1st point
assert_eq!(a2, 177.48784020815515); // Azimuth at 2nd point (forward)
Source

pub fn direct( &self, lat1: f64, lon1: f64, azi1: f64, s12: f64, ) -> (f64, f64, f64)

Compute a new location (lat2,lon2) from (lat1,lon1) a distance s12 at an azimuth of azi1

§Arguments
  • lat1 - Latitude of 1st point [degrees] [-90.,90.]
  • lon1 - Longitude of 1st point [degrees] [-180., 180.]
  • azi1 - Azimuth at 1st point [degrees] [-180., 180.]
  • s12 - Distance from 1st to 2nd point [meters] Value may be negative
§Returns
  • lat2 - Latitude of 2nd point [degrees]
  • lon2 - Longitude of 2nd point [degrees]
  • azi2 - Azimuth at 2nd point

If either point is at a pole, the azimuth is defined by keeping the longitude fixed, writing lat = ±(90° − ε), and taking the limit ε → 0+. An arc length greater that 180° signifies a geodesic which is not a shortest path. (For a prolate ellipsoid, an additional condition is necessary for a shortest path: the longitudinal extent must not exceed of 180°.)

// Example, determine the point 10000 km NE of JFK:
use geographiclib::Geodesic;
let g = Geodesic::wgs84();
let (lat,lon,az) = g.direct(40.64, -73.78, 45.0, 10e6);
assert_eq!(lat, 32.621100463725796);
assert_eq!(lon, 49.05248709295982);
assert_eq!(az,  140.4059858768007);

Trait Implementations§

Source§

impl Debug for Geodesic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Geodesic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.