Astronomy
The AstronomyExtensions class provides extension methods for astronomical calculations: distance conversions, Julian date, sidereal time, and horizontal ↔ equatorial coordinate transforms.
📏 Distance Conversions
Convert between light-years, parsecs, and astronomical units:
double pc = 4.37.LightYearsToParsecs(); // Proxima Centauri ≈ 1.34 pc
double ly = 1.0.ParsecsToLightYears(); // 1 pc ≈ 3.26 ly
double au = 1.0.LightYearsToAU(); // 1 ly ≈ 63241 AU
double au2 = 1.0.ParsecsToAU(); // 1 pc ≈ 206265 AU
📅 Julian Date
Compute Julian Date and Julian centuries since J2000.0:
var utc = new DateTime(2024, 6, 15, 21, 0, 0, DateTimeKind.Utc);
double jd = utc.ToJulianDate(); // Julian Date
double T = utc.JulianCenturiesSinceJ2000(); // centuries since J2000.0
⏱️ Sidereal Time
Compute Greenwich and local sidereal time from UTC, or from local time with time zone:
var utc = new DateTime(2024, 6, 15, 21, 0, 0, DateTimeKind.Utc);
double gmst = utc.GreenwichMeanSiderealTimeHours(); // GMST in hours
double gmstDeg = utc.GreenwichMeanSiderealTimeDegrees(); // GMST in degrees
// Local sidereal time (Stockholm: 18.07° E)
double lmst = utc.LocalMeanSiderealTimeHours(18.07);
// From local time + time zone + longitude
var local = new DateTime(2024, 6, 15, 23, 0, 0);
double lst = local.LocalSiderealTimeFromLocal(
utcOffsetHours: 2.0, // UTC+2 (CEST)
longitudeDegrees: 18.07); // Stockholm
⬆️ Horizontal → Equatorial (Altitude/Azimuth → RA/Dec)
Convert what you observe (altitude, azimuth) to sky coordinates (right ascension, declination):
// Using explicit local sidereal time
var (ra, dec) = AstronomyExtensions.HorizontalToEquatorial(
altitudeDegrees: 45.0,
azimuthDegrees: 180.0, // due south
latitudeDegrees: 51.48, // London
localSiderealTimeDegrees: 120.0);
// Using UTC time and longitude (LST computed automatically)
var utc = new DateTime(2024, 3, 20, 22, 0, 0, DateTimeKind.Utc);
var (ra2, dec2) = AstronomyExtensions.HorizontalToEquatorial(
altitudeDegrees: 45.0,
azimuthDegrees: 180.0,
latitudeDegrees: 51.48,
longitudeDegrees: 0.0, // Greenwich
utc: utc);
⬇️ Equatorial → Horizontal (RA/Dec → Altitude/Azimuth)
Find where a star appears in the sky from your location:
var (alt, az) = AstronomyExtensions.EquatorialToHorizontal(
rightAscensionDegrees: 200.0,
declinationDegrees: 30.0,
latitudeDegrees: 59.33, // Stockholm
localSiderealTimeDegrees: 120.0);
// Or with UTC + position
var (alt2, az2) = AstronomyExtensions.EquatorialToHorizontal(
rightAscensionDegrees: 200.0,
declinationDegrees: 30.0,
latitudeDegrees: 59.33,
longitudeDegrees: 18.07,
utc: utc);
📐 Angle Helpers
Convert between common astronomical angle formats:
// Right ascension: hours/min/sec ↔ degrees
double deg = AstronomyExtensions.RightAscensionToDegrees(6, 30, 0); // → 97.5°
var (h, m, s) = AstronomyExtensions.DegreesToRightAscension(97.5); // → (6, 30, 0.0)
// Declination: degrees/arcmin/arcsec → decimal degrees
double dec = AstronomyExtensions.DeclinationToDegrees(-16, 42, 58); // → -16.7161°