coord

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Galactic = InertialFrame{Name: "Galactic", Matrix: GalacticMatrix}
	B1950    = InertialFrame{Name: "B1950", Matrix: B1950Matrix}

	// Ecliptic is the J2000 mean ecliptic frame. This rotates ICRF around the
	// X-axis by the J2000 mean obliquity (23.4393°).
	Ecliptic = InertialFrame{
		Name: "Ecliptic",
		Matrix: [3][3]float64{
			{1, 0, 0},
			{0, obliquityCos, obliquitySin},
			{0, -obliquitySin, obliquityCos},
		},
	}
)

Predefined InertialFrame instances for common reference frames.

View Source
var B1950Matrix = [3][3]float64{
	{0.99992570795236291, 0.011178938126427691, 0.0048590038414544293},
	{-0.011178938137770135, 0.9999375133499887, -2.715792625851078e-05},
	{-0.0048590038153592712, -2.7162594714247048e-05, 0.9999881946023742},
}

B1950Matrix is the rotation matrix from ICRF (J2000) to the mean equator and equinox of B1950 (FK4). Apply as v_B1950 = B1950Matrix * v_icrf. Source: SPICE Toolkit / Skyfield.

View Source
var GalacticMatrix = [3][3]float64{
	{-0.054875539395742523, -0.87343710472759606, -0.48383499177002515},
	{0.49410945362774389, -0.44482959429757496, 0.74698224869989183},
	{-0.86766613568337381, -0.19807638961301985, 0.45598379452141991},
}

GalacticMatrix is the rotation matrix from ICRF (J2000) to Galactic System II (IAU 1958). Apply as v_gal = GalacticMatrix * v_icrf. Source: SPICE Toolkit / Skyfield.

View Source
var ICRSToJ2000Matrix [3][3]float64

ICRSToJ2000Matrix is the frame bias matrix from ICRS to the dynamical mean equator and equinox of J2000. The bias is a few milliarcseconds. Source: IERS Conventions 2003, Chapter 5.

Functions

func Aberration

func Aberration(position, velocity [3]float64, lightTime float64) [3]float64

Aberration applies special-relativistic stellar aberration to an astrometric position vector. Uses the full Lorentz transformation (not the classical v/c approximation). Matches Skyfield's add_aberration() in relativity.py.

position is the observer-to-target vector in km (astrometric position). velocity is the observer's barycentric velocity in km/day. lightTime is the light travel time to the target in days.

Returns the apparent position in km.

func Altaz

func Altaz(posICRF [3]float64, latDeg, lonDeg, jdUT1 float64) (altDeg, azDeg, distKm float64)

Altaz converts a geocentric ICRF position vector to altitude and azimuth for a ground observer at the given geodetic latitude and longitude. jdUT1 is the UT1 Julian date (needed for Earth rotation).

The position should be a geocentric or topocentric vector in km (typically from SPK.Apparent). For distant bodies (Sun, planets), geocentric and topocentric directions agree to <0.01°. For the Moon, topocentric positions are needed for arcsecond-level accuracy (parallax ~1°).

Returns altitude (degrees, positive above horizon, geometric — no refraction), azimuth (degrees, 0=North, 90=East), and distance (km).

The rotation chain is: ICRF → mean equator of date (precession) → true equator of date (nutation) → ITRF (Earth rotation via GAST) → local horizon (lat/lon). Matches Skyfield's rotation_at() + altaz() pipeline.

func Deflection

func Deflection(position, pe [3]float64, rmass float64) [3]float64

Deflection computes the gravitational deflection of light by a single body. Returns the deflection correction vector in km (to be added to the position).

position is the observer-to-target vector in km (astrometric position). pe is the observer-to-deflector vector in km (same sign convention as Skyfield). rmass is the reciprocal mass: GM_sun / GM_deflector (1.0 for the Sun).

Matches Skyfield's _compute_deflection() in relativity.py.

func EarthRotationAngle

func EarthRotationAngle(jdUT1 float64) float64

EarthRotationAngle returns the Earth Rotation Angle in degrees for a given UT1 Julian date. Uses the formula from IAU Resolution B1.8 of 2000. This is the modern replacement for GMST.

func Elongation

func Elongation(targetLonDeg, referenceLonDeg float64) float64

Elongation returns the elongation of a target from a reference body, given their ecliptic longitudes in degrees. Returns degrees in [0, 360). For moon phase, pass the Moon's ecliptic longitude as target and the Sun's as reference: 0°=new moon, 90°=first quarter, 180°=full, 270°=last quarter.

func FractionIlluminated

func FractionIlluminated(phaseAngleDeg float64) float64

FractionIlluminated returns the fraction of a spherical body's disc that is illuminated, given the phase angle in degrees. Returns a value in [0, 1].

func GAST

func GAST(jdUT1 float64) float64

GAST returns Greenwich Apparent Sidereal Time in degrees, which includes the nutation correction (equation of equinoxes).

func GMST

func GMST(jdUT1 float64) float64

GMST returns Greenwich Mean Sidereal Time in degrees for a given UT1 Julian date. Uses the IAU 1982 formula (Meeus).

func GeodeticToICRF

func GeodeticToICRF(latDeg, lonDeg, jdUT1 float64) (x, y, z float64)

GeodeticToICRF converts geodetic coordinates (lat/lon in degrees) to an ICRF direction vector at the given UT1 Julian date. Uses the full transformation: ICRF = P^T * N^T * Rz(GAST) * ITRF

func HourAngleDec

func HourAngleDec(posICRF [3]float64, lonDeg, jdUT1 float64) (haDeg, decDeg float64)

HourAngleDec computes the hour angle and declination of a geocentric ICRF position vector for an observer at the given longitude. jdUT1 is the UT1 Julian date.

Hour angle is measured westward from the local meridian (0° = on meridian, positive = west of meridian). Declination is measured from the true equator of date.

Returns hour angle (degrees, 0–360) and declination (degrees, -90 to +90).

func ICRFToEcliptic

func ICRFToEcliptic(x, y, z float64) (latDeg, lonDeg float64)

ICRFToEcliptic converts an ICRF Cartesian vector to ecliptic latitude and longitude (degrees). Uses the J2000 mean ecliptic (matching Skyfield's default ecliptic_latlon()).

func ICRFToGalactic

func ICRFToGalactic(x, y, z float64) (latDeg, lonDeg float64)

ICRFToGalactic converts an ICRF Cartesian vector to Galactic latitude and longitude in degrees. Longitude is in [0, 360).

func ITRFToGeodetic

func ITRFToGeodetic(x, y, z float64) (latDeg, lonDeg, heightKm float64)

ITRFToGeodetic converts ITRF Cartesian coordinates (km) to geodetic latitude, longitude (degrees), and height above the WGS84 ellipsoid (km).

Uses Bowring's iterative method (converges in 2-3 iterations for terrestrial positions, and handles all cases including poles and equator).

func IsBehindEarth

func IsBehindEarth(observerPosKm, targetPosKm [3]float64) bool

IsBehindEarth returns true if the target position is geometrically behind Earth as seen from the observer position.

Both positions are geocentric ICRF vectors in km. The target is "behind Earth" if the line of sight from observer to target passes through Earth's sphere.

func IsSunlit

func IsSunlit(posKm, sunPosKm [3]float64) bool

IsSunlit returns true if a position (in km, ICRF, relative to Earth center) is illuminated by the Sun.

posKm is the object's geocentric position in km (e.g., a satellite). sunPosKm is the Sun's geocentric position in km (from SPK.Observe or SPK.Apparent).

Uses geometric shadow test: the object is in shadow if the line from the object to the Sun intersects Earth's sphere.

func PhaseAngle

func PhaseAngle(obsToTarget, sunToTarget [3]float64) float64

PhaseAngle returns the phase angle in degrees given two direction vectors: obsToTarget (observer to target) and sunToTarget (Sun to target). The phase angle is 0° when fully illuminated and 180° when fully in shadow.

To compute sunToTarget from goeph's SPK package:

obsToTarget := spk.Observe(targetID, tdb)
obsToSun := spk.Observe(spk.Sun, tdb)
sunToTarget := [3]float64{obsToTarget[0]-obsToSun[0], obsToTarget[1]-obsToSun[1], obsToTarget[2]-obsToSun[2]}

func PositionAngle

func PositionAngle(ra1Hours, dec1Deg, ra2Hours, dec2Deg float64) float64

PositionAngle returns the position angle from one sky position to another, measured North through East (counterclockwise on the sky), in degrees [0, 360). Both positions are given as RA (hours) and Dec (degrees).

func RADecToICRF

func RADecToICRF(raHours, decDeg float64) (x, y, z float64)

RADecToICRF converts J2000 RA (hours) and Dec (degrees) to an ICRF unit vector.

func Refract

func Refract(altDeg, tempC, pressureMbar float64) float64

Refract returns the apparent altitude in degrees after atmospheric refraction, given a true (geometric) altitude. Uses iterative convergence of Bennett's formula (within 3e-5 degrees, ~0.1 arcsecond).

Parameters:

  • altDeg: true (geometric) altitude in degrees
  • tempC: temperature in degrees Celsius
  • pressureMbar: atmospheric pressure in millibars

func Refraction

func Refraction(altDeg, tempC, pressureMbar float64) float64

Refraction returns the atmospheric refraction correction in degrees for a given apparent (observed) altitude. Uses Bennett's formula (1982). Returns 0 for altitudes below -1° or above 89.9°.

Parameters:

  • altDeg: apparent altitude in degrees
  • tempC: temperature in degrees Celsius
  • pressureMbar: atmospheric pressure in millibars

func SeparationAngle

func SeparationAngle(a, b [3]float64) float64

SeparationAngle returns the angular separation in degrees between two Cartesian vectors. Uses Kahan's numerically stable formula. See: https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf Section 12.

func SetNutationPrecision

func SetNutationPrecision(p NutationPrecision)

SetNutationPrecision sets the nutation precision for the coord package. Default is NutationStandard (30 terms, fast). Not safe for concurrent use — call once at program startup.

func TEMEToICRF

func TEMEToICRF(posKmTEME [3]float64, jdUT1 float64) [3]float64

TEMEToICRF converts a TEME (True Equator, Mean Equinox) position vector from SGP4 propagation to ICRF/GCRS coordinates.

posKmTEME is the satellite position in km from SGP4 (TEME frame). jdUT1 is the UT1 Julian date (used for Earth rotation via nutation/precession).

The TEME frame is the output frame of SGP4. It uses the true equator of date but a "mean" equinox that differs from the classical mean equinox by the equation of the equinoxes. The conversion chain is:

TEME → true equator of date (via equation of equinoxes rotation)
     → mean equator of date (via nutation inverse)
     → ICRF/J2000 (via precession inverse)

Types

type InertialFrame

type InertialFrame struct {
	Name   string
	Matrix [3][3]float64 // ICRF → frame rotation matrix
}

InertialFrame is a static (time-independent) reference frame defined by a rotation matrix from ICRF. Examples include the Galactic frame, B1950, and the ecliptic. Apply the rotation matrix to an ICRF vector to get coordinates in this frame.

func (InertialFrame) LatLon

func (f InertialFrame) LatLon(posICRF [3]float64) (latDeg, lonDeg float64)

LatLon applies the frame rotation to an ICRF position vector, returning latitude and longitude in degrees. Longitude is in [0, 360).

func (InertialFrame) XYZ

func (f InertialFrame) XYZ(posICRF [3]float64) [3]float64

XYZ applies the frame rotation to an ICRF position vector, returning Cartesian coordinates in this frame.

type Location

type Location struct {
	Name string
	Lat  float64 // degrees, positive north
	Lon  float64 // degrees, positive east
}

Location represents a ground location with WGS84 coordinates.

type NutationPrecision

type NutationPrecision int

NutationPrecision controls the number of terms used in the IAU 2000A nutation series.

const (
	// NutationStandard uses the 30 largest luni-solar terms (~1 arcsec precision).
	// This is ~45x faster than NutationFull and sufficient for most applications,
	// since other error sources (light-time ~20 arcsec, GMST formula ~0.3 arcsec/century)
	// dominate the overall accuracy budget.
	NutationStandard NutationPrecision = iota

	// NutationFull uses all 678 luni-solar + 687 planetary terms (~0.001 arcsec precision).
	// Matches Skyfield's default IAU 2000A nutation model. Use for high-precision
	// single-point computations or when exact Skyfield parity is required.
	NutationFull
)

func GetNutationPrecision

func GetNutationPrecision() NutationPrecision

GetNutationPrecision returns the current nutation precision setting.

type TimeBasedFrame

type TimeBasedFrame struct {
	Name     string
	MatrixAt func(jd float64) [3][3]float64 // ICRF → frame rotation matrix at time jd
}

TimeBasedFrame is a time-dependent reference frame defined by a function that returns a rotation matrix from ICRF at a given Julian date. Examples include the true equator of date and the ITRF (Earth-fixed frame).

func ITRFFrame

func ITRFFrame() TimeBasedFrame

ITRFFrame returns a TimeBasedFrame for the International Terrestrial Reference Frame (Earth-fixed). The jd argument is UT1 Julian date.

func (TimeBasedFrame) LatLon

func (f TimeBasedFrame) LatLon(posICRF [3]float64, jd float64) (latDeg, lonDeg float64)

LatLon applies the frame rotation at the given Julian date to an ICRF position vector, returning latitude and longitude in degrees. Longitude is in [0, 360).

func (TimeBasedFrame) XYZ

func (f TimeBasedFrame) XYZ(posICRF [3]float64, jd float64) [3]float64

XYZ applies the frame rotation at the given Julian date to an ICRF position vector, returning Cartesian coordinates in this frame.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL