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: f64Geodetic latitude in radians. North is positive.
longitude: f64Geodetic longitude in radians. East is positive.
height: f64Height above WGS84 ellipsoid in meters.
Implementations§
Source§impl Location
impl Location
Sourcepub fn new(latitude: f64, longitude: f64, height: f64) -> AstroResult<Self>
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.
Sourcepub fn from_degrees(
lat_deg: f64,
lon_deg: f64,
height_m: f64,
) -> AstroResult<Self>
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)?;Sourcepub fn latitude_degrees(&self) -> f64
pub fn latitude_degrees(&self) -> f64
Returns the latitude in degrees.
Sourcepub fn longitude_degrees(&self) -> f64
pub fn longitude_degrees(&self) -> f64
Returns the longitude in degrees.
Sourcepub fn latitude_angle(&self) -> Angle
pub fn latitude_angle(&self) -> Angle
Returns the latitude as an Angle.
Sourcepub fn longitude_angle(&self) -> Angle
pub fn longitude_angle(&self) -> Angle
Returns the longitude as an Angle.
Source§impl Location
impl Location
Sourcepub fn to_geocentric_km(&self) -> AstroResult<(f64, f64)>
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 axisv: 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.
Sourcepub fn to_geocentric_meters(&self) -> AstroResult<(f64, f64)>
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 axisv: 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);