Skip to main content

Location

Struct Location 

Source
pub struct Location {
    pub latitude: f64,
    pub longitude: f64,
    pub height: f64,
}
Expand description

A geographic location on Earth in WGS84 geodetic coordinates.

All angular values are stored internally in radians. Use Location::from_degrees for convenience when working with degree-based coordinates.

Fields§

§latitude: f64

Geodetic latitude in radians. North is positive.

§longitude: f64

Geodetic longitude in radians. East is positive.

§height: f64

Height above WGS84 ellipsoid in meters.

Implementations§

Source§

impl Location

Source

pub fn new(latitude: f64, longitude: f64, height: f64) -> AstroResult<Self>

Creates a new location from coordinates in radians.

§Arguments
  • latitude - Geodetic latitude in radians, must be in [-pi/2, pi/2]
  • longitude - Geodetic longitude in radians, must be in [-pi, pi]
  • height - Height above WGS84 ellipsoid in meters, must be in [-12000, 100000]
§Errors

Returns an error if any coordinate is non-finite or outside its valid range. The height range covers the Mariana Trench floor to well above aircraft altitude.

Source

pub fn from_degrees( lat_deg: f64, lon_deg: f64, height_m: f64, ) -> AstroResult<Self>

Creates a new location from coordinates in degrees.

This is the typical way to create a Location, since most sources provide coordinates in degrees.

§Arguments
  • lat_deg - Geodetic latitude in degrees, must be in [-90, 90]
  • lon_deg - Geodetic longitude in degrees, must be in [-180, 180]
  • height_m - Height above WGS84 ellipsoid in meters
§Example
use celestial_core::Location;

// La Silla Observatory, Chile
let la_silla = Location::from_degrees(-29.2563, -70.7380, 2400.0)?;
Source

pub fn latitude_degrees(&self) -> f64

Returns the latitude in degrees.

Source

pub fn longitude_degrees(&self) -> f64

Returns the longitude in degrees.

Source

pub fn latitude_angle(&self) -> Angle

Returns the latitude as an Angle.

Source

pub fn longitude_angle(&self) -> Angle

Returns the longitude as an Angle.

Source

pub fn greenwich() -> Self

Returns the Royal Observatory, Greenwich (0, 0, 0).

Useful as a default or reference location.

Source§

impl Location

Source

pub fn to_geocentric_km(&self) -> AstroResult<(f64, f64)>

Converts geodetic coordinates to geocentric cylindrical coordinates in kilometers.

Uses the WGS84 ellipsoid to compute the observer’s position relative to Earth’s center of mass. The result accounts for Earth’s equatorial bulge.

§Returns

(u, v) in kilometers where:

  • u: perpendicular distance from Earth’s rotation axis
  • v: distance from the equatorial plane (positive north)
§Example
use celestial_core::Location;

let obs = Location::from_degrees(45.0, 0.0, 0.0)?;
let (u, v) = obs.to_geocentric_km()?;

// At 45 degrees, u and v are similar but u > v due to Earth's shape
assert!(u > 4500.0 && u < 4600.0);
assert!(v > 4400.0 && v < 4500.0);
§Errors

Returns an error for degenerate latitude values that would cause division by zero. In practice, this is unlikely with validated Location values.

Source

pub fn to_geocentric_meters(&self) -> AstroResult<(f64, f64)>

Converts geodetic coordinates to geocentric cylindrical coordinates in meters.

Same algorithm as to_geocentric_km but returns results in meters for applications requiring higher precision or SI units.

This method uses a slightly different formulation internally (computing the flattening ratio explicitly) but produces equivalent results to the km version.

§Returns

(u, v) in meters where:

  • u: perpendicular distance from Earth’s rotation axis
  • v: distance from the equatorial plane (positive north)
§Example
use celestial_core::Location;

// Equator at sea level
let equator = Location::from_degrees(0.0, 0.0, 0.0)?;
let (u, v) = equator.to_geocentric_meters()?;

// At equator: u equals semi-major axis, v is zero
assert!((u - 6_378_137.0).abs() < 1.0);
assert!(v.abs() < 1e-9);

Trait Implementations§

Source§

impl Clone for Location

Source§

fn clone(&self) -> Location

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Location

Source§

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

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

impl PartialEq for Location

Source§

fn eq(&self, other: &Location) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Location

Source§

impl StructuralPartialEq for Location

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.