Observer locations
Anything you compute for a telescope, such as hour angle, altitude or the Moon’s parallax,
depends on where the telescope is. Location holds that: a geodetic latitude, longitude
and height on the WGS84 ellipsoid, the same coordinates a GPS receiver reports.
use celestial_core::location::Location;
// Mauna Kea: latitude, longitude (east positive), height above the WGS84 ellipsoid
let site = Location::from_degrees(19.8207, -155.4681, 4205.0)?;
site.latitude_degrees(); // 19.8207
site.longitude_degrees(); // -155.4681
site.height(); // 4205.0, meters
site.latitude(); // 0.34593647505004005, radians
site.latitude_angle(); // an Angle
Location is Copy. You build it once per site and pass it to celestial-coords and
celestial-time wherever they need an observer.
Conventions
- Latitude is north positive, from -90° to +90°.
- Longitude is east positive, from -180° to +180°. West longitudes are negative.
- Height is in meters above the WGS84 ellipsoid, not above sea level. The two differ by the local geoid height, which can be tens of meters. For most astronomy that error doesn’t matter, but use the ellipsoid height from a GPS fix when you have it.
Location stores radians. new(latitude, longitude, height) takes radians directly, and
from_degrees converts with correct rounding, so 45° becomes exactly the f64 nearest
π/4.
East longitudes from 0° to 360°
Some observatory lists give longitude east from 0° to 360°. from_degrees accepts that
form and stores the equivalent value in the -180° to +180° range:
use celestial_core::location::Location;
let west = Location::from_degrees(19.8207, -155.4681, 4205.0)?;
let east = Location::from_degrees(19.8207, 204.5319, 4205.0)?;
east.longitude_degrees(); // -155.4681
west == east; // true
new doesn’t do this. Radians outside -π to π are an error.
Validation
Both constructors check their input and return an AstroError for anything that
isn’t a place an observer could be:
use celestial_core::location::Location;
let err = Location::from_degrees(95.0, 10.0, 0.0).unwrap_err();
println!("{err}");
// Math error in location_validation (out of range): Latitude outside valid range [-90°, +90°]
let err = Location::from_degrees(19.8207, -155.4681, f64::NAN).unwrap_err();
println!("{err}");
// Math error in location_validation (not finite): Height must be finite
Height must fall between -12,000 m and 100,000 m. That covers the floor of the Mariana Trench and balloon altitudes. It won’t catch a height given in feet or kilometers, because those usually land inside the range too.
With the serde feature, deserializing runs the same checks. The fields are latitude,
longitude and height, in radians and meters. A file written in degrees usually
fails to load instead of loading as the wrong place:
use celestial_core::location::Location;
let json = r#"{"latitude": 0.3459, "longitude": -2.7134, "height": 4205.0}"#;
let site: Location = serde_json::from_str(json)?;
let bad = r#"{"latitude": 19.8, "longitude": -155.5, "height": 4205.0}"#;
assert!(serde_json::from_str::<Location>(bad).is_err()); // degrees, not radians
Position relative to the Earth’s center
Geodetic latitude is the angle of the ellipsoid’s surface normal, not the angle from the Earth’s center. Because the Earth bulges at the equator, the two differ by up to about 11 arcminutes. Parallax needs the second kind: where the observer is in space.
to_geocentric_meters and to_geocentric_km return that position as (u, v): u is
the distance from the rotation axis and v the distance from the equatorial plane,
positive north.
use celestial_core::location::Location;
use celestial_core::matrix::Vector3;
use celestial_core::angle::Angle;
let site = Location::from_degrees(19.8207, -155.4681, 4205.0)?;
let (u, v) = site.to_geocentric_km();
println!("u = {u:.3} km, v = {v:.3} km");
// u = 6006.552 km, v = 2150.460 km
let (_, geocentric_lat) = Vector3::new(u, 0.0, v).to_spherical();
println!("{:.4}°", Angle::from_radians(geocentric_lat).degrees());
// 19.6983°
At Mauna Kea the geocentric latitude is 0.12° south of the geodetic one. For the Moon,
whose diurnal parallax reaches about 1°, that offset matters. celestial-coords uses
to_geocentric_meters for its diurnal parallax correction.
The conversion matches ERFA’s gd2gce on the WGS84 ellipsoid. For Cartesian
coordinates in an Earth-fixed frame, rotate by longitude: x = u·cos(lon),
y = u·sin(lon), z = v.
Edge cases
Location::greenwich()returns latitude 0, longitude 0 and height 0. That point is on the Greenwich meridian at the equator, not at the Royal Observatory, which is at about 51.48° N.- Longitudes from 180° to 360° are wrapped by
from_degreesonly. Values below -180° are an error in both constructors.
Where next
- Angles for
latitude_angle()andlongitude_angle(), and for parsing site coordinates from strings. - Precession, nutation and obliquity for the Earth-side models that combine with a location to give hour angle and altitude.