feat: 完善时标与天象几何计算并扩展输出接口

- 新增时标、ΔT 模型、质心时间与 UT1 支持
- 改进日月食、月掩、行星事件及路径边界计算
- 完善恒星三维自行与动态距离传播
- 扩展 SVG、GeoJSON、KML 输出与底层距离换算工具
- 整理中英文手册、示例资源及回归测试
This commit is contained in:
2026-09-23 18:55:12 +08:00
parent 1f31a9b5b5
commit 16c62a97d5
503 changed files with 33290 additions and 9471 deletions
+8 -6
View File
@@ -5,6 +5,8 @@ import (
"math"
. "b612.me/astro/tools"
"b612.me/astro/basic"
)
const (
@@ -17,8 +19,8 @@ var (
ErrNotOnThisDate = errors.New("rise/set event occurs on adjacent date")
)
func MeanObliquity(jd float64) float64 {
t := (jd - 2451545.0) / 36525.0
func MeanObliquity(jde float64) float64 {
t := (jde - 2451545.0) / 36525.0
return 23.4392911111 - (46.8150*t+0.00059*t*t-0.001813*t*t*t)/3600.0
}
@@ -27,8 +29,8 @@ func MeanSiderealTime(jd float64) float64 {
return Limit360(280.46061837 + 360.98564736629*(jd-2451545.0) + 0.000387933*t*t - t*t*t/38710000.0)
}
func EclipticToEquatorial(jd, lo, bo float64) (float64, float64) {
eps := MeanObliquity(jd)
func EclipticToEquatorial(jde, lo, bo float64) (float64, float64) {
eps := MeanObliquity(jde)
ra := math.Atan2(Sin(lo)*Cos(eps)-Tan(bo)*Sin(eps), Cos(lo)) * 180.0 / math.Pi
if ra < 0 {
ra += 360
@@ -38,7 +40,7 @@ func EclipticToEquatorial(jd, lo, bo float64) (float64, float64) {
}
func HorizontalCoordinates(ra, dec, jd, lon, lat float64) (float64, float64, float64) {
lst := Limit360(MeanSiderealTime(jd) + lon)
lst := Limit360(MeanSiderealTime(basic.UTC2UT1(jd)) + lon)
hourAngle := Limit360(lst - ra)
altitude := ArcSin(clampUnit(Sin(lat)*Sin(dec) + Cos(lat)*Cos(dec)*Cos(hourAngle)))
@@ -63,7 +65,7 @@ func TopocentricRaDec(ra, dec, observerLat, observerLon, jd, distanceEarthRadii,
rhoCos := math.Cos(u) + heightMeters/6378140.0*Cos(observerLat)
parallax := math.Asin(1.0 / distanceEarthRadii)
hourAngle := (Limit360(MeanSiderealTime(jd) + observerLon - ra)) * math.Pi / 180.0
hourAngle := (Limit360(MeanSiderealTime(basic.UTC2UT1(jd)) + observerLon - ra)) * math.Pi / 180.0
decRad := dec * math.Pi / 180.0
numerator := -rhoCos * math.Sin(parallax) * math.Sin(hourAngle)
+23 -22
View File
@@ -2,47 +2,48 @@ package internal
import . "b612.me/astro/tools"
func SunLo(jd float64) float64 {
t := (jd - 2451545.0) / 365250.0
func SunLo(jde float64) float64 {
t := (jde - 2451545.0) / 365250.0
return Limit360(280.4664567 + 360007.6982779*t + 0.03032028*t*t + t*t*t/49931.0 - t*t*t*t/15299.0 - t*t*t*t*t/1988000.0)
}
func SunMeanAnomaly(jd float64) float64 {
t := (jd - 2451545.0) / 36525.0
func SunMeanAnomaly(jde float64) float64 {
t := (jde - 2451545.0) / 36525.0
return Limit360(357.5291092 + 35999.0502909*t - 0.0001559*t*t - 0.00000048*t*t*t)
}
func EarthEccentricity(jd float64) float64 {
t := (jd - 2451545.0) / 36525.0
func EarthEccentricity(jde float64) float64 {
t := (jde - 2451545.0) / 36525.0
return 0.016708617 - 0.000042037*t - 0.0000001236*t*t
}
func SunCenter(jd float64) float64 {
t := (jd - 2451545.0) / 36525.0
m := SunMeanAnomaly(jd)
func SunCenter(jde float64) float64 {
t := (jde - 2451545.0) / 36525.0
m := SunMeanAnomaly(jde)
return (1.9146-0.004817*t-0.000014*t*t)*Sin(m) + (0.019993-0.000101*t)*Sin(2*m) + 0.00029*Sin(3*m)
}
func SunTrueLo(jd float64) float64 {
return Limit360(SunLo(jd) + SunCenter(jd))
// 本文件以 jde(力学时儒略日)键控;lite 包装层的实参是 UTC 民用 JD,69 s 的历元差远低于轻量公式精度。
func SunTrueLo(jde float64) float64 {
return Limit360(SunLo(jde) + SunCenter(jde))
}
func SunApparentLo(jd float64) float64 {
t := (jd - 2451545.0) / 36525.0
return Limit360(SunTrueLo(jd) - 0.00569 - 0.00478*Sin(125.04-1934.136*t))
func SunApparentLo(jde float64) float64 {
t := (jde - 2451545.0) / 36525.0
return Limit360(SunTrueLo(jde) - 0.00569 - 0.00478*Sin(125.04-1934.136*t))
}
func SunDistanceAU(jd float64) float64 {
c := SunCenter(jd)
m := SunMeanAnomaly(jd)
e := EarthEccentricity(jd)
func SunDistanceAU(jde float64) float64 {
c := SunCenter(jde)
m := SunMeanAnomaly(jde)
e := EarthEccentricity(jde)
return 1.000001018 * (1 - e*e) / (1 + e*Cos(m+c))
}
func SunTrueRaDec(jd float64) (float64, float64) {
return EclipticToEquatorial(jd, SunTrueLo(jd), 0)
func SunTrueRaDec(jde float64) (float64, float64) {
return EclipticToEquatorial(jde, SunTrueLo(jde), 0)
}
func SunApparentRaDec(jd float64) (float64, float64) {
return EclipticToEquatorial(jd, SunApparentLo(jd), 0)
func SunApparentRaDec(jde float64) (float64, float64) {
return EclipticToEquatorial(jde, SunApparentLo(jde), 0)
}
+27 -16
View File
@@ -1,6 +1,7 @@
package moon
import (
"b612.me/astro/internal/civiltime"
"errors"
"math"
"time"
@@ -18,50 +19,50 @@ var (
// TrueLo 轻量真黄经 / lightweight true ecliptic longitude.
func TrueLo(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JDE(date.UTC())).Longitude
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).Longitude
}
// TrueBo 轻量真黄纬 / lightweight true ecliptic latitude.
func TrueBo(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JDE(date.UTC())).Latitude
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).Latitude
}
// TrueRa 轻量真赤经 / lightweight true right ascension.
func TrueRa(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JDE(date.UTC())).RightAscension
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).RightAscension
}
// TrueDec 轻量真赤纬 / lightweight true declination.
func TrueDec(date time.Time) float64 {
return lite.MoonGeocentric(basic.Date2JDE(date.UTC())).Declination
return lite.MoonGeocentric(basic.Date2JD(date.UTC())).Declination
}
// TrueRaDec 轻量真赤经、真赤纬 / lightweight true right ascension and declination.
func TrueRaDec(date time.Time) (float64, float64) {
state := lite.MoonGeocentric(basic.Date2JDE(date.UTC()))
state := lite.MoonGeocentric(basic.Date2JD(date.UTC()))
return state.RightAscension, state.Declination
}
// ApparentRa 轻量站心视赤经 / lightweight topocentric apparent right ascension.
func ApparentRa(date time.Time, lon, lat float64) float64 {
state := lite.MoonTopocentric(basic.Date2JDE(date.UTC()), lon, lat, 0)
state := lite.MoonTopocentric(basic.Date2JD(date.UTC()), lon, lat, 0)
return state.RightAscension
}
// ApparentDec 轻量站心视赤纬 / lightweight topocentric apparent declination.
func ApparentDec(date time.Time, lon, lat float64) float64 {
state := lite.MoonTopocentric(basic.Date2JDE(date.UTC()), lon, lat, 0)
state := lite.MoonTopocentric(basic.Date2JD(date.UTC()), lon, lat, 0)
return state.Declination
}
// ApparentRaDec 轻量站心视赤经、视赤纬 / lightweight topocentric apparent right ascension and declination.
func ApparentRaDec(date time.Time, lon, lat float64) (float64, float64) {
state := lite.MoonTopocentric(basic.Date2JDE(date.UTC()), lon, lat, 0)
state := lite.MoonTopocentric(basic.Date2JD(date.UTC()), lon, lat, 0)
return state.RightAscension, state.Declination
}
func topocentricHorizontal(date time.Time, lon, lat float64) (altitude, azimuth, hourAngle float64) {
jd := basic.Date2JDE(date.UTC())
jd := basic.Date2JD(date.UTC())
state := lite.MoonTopocentric(jd, lon, lat, 0)
return lite.HorizontalCoordinates(state.RightAscension, state.Declination, jd, lon, lat)
}
@@ -92,8 +93,8 @@ func Zenith(date time.Time, lon, lat float64) float64 {
// SunMoonLoDiff 轻量日月黄经差 / lightweight Moon-Sun ecliptic-longitude difference.
func SunMoonLoDiff(date time.Time) float64 {
jd := basic.Date2JDE(date.UTC())
return Limit360(lite.MoonGeocentric(jd).Longitude - lite.SunApparentLo(jd))
jdUTC := basic.Date2JD(date.UTC())
return Limit360(lite.MoonGeocentric(jdUTC).Longitude - lite.SunApparentLo(jdUTC))
}
// PhaseAge 轻量月龄 / lightweight lunar age in days.
@@ -108,26 +109,36 @@ func Phase(date time.Time) float64 {
// RiseTime 轻量月出时刻 / lightweight moonrise time.
func RiseTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
if result, err, handled := civiltime.Event(date, ERR_NOT_TODAY, func(d time.Time) (time.Time, error) {
return RiseTime(d, lon, lat, height, aero)
}); handled {
return result, err
}
return riseSetTime(date, lon, lat, height, aero, true)
}
// SetTime 轻量月落时刻 / lightweight moonset time.
func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
if result, err, handled := civiltime.Event(date, ERR_NOT_TODAY, func(d time.Time) (time.Time, error) {
return SetTime(d, lon, lat, height, aero)
}); handled {
return result, err
}
return riseSetTime(date, lon, lat, height, aero, false)
}
func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (time.Time, error) {
localMidnight := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
localJD := basic.Date2JDE(localMidnight)
localJD := basic.Date2JD(localMidnight)
_, offset := localMidnight.Zone()
timezone := float64(offset) / 3600.0
horizonDip := basic.HeightDegreeByLat(height, lat)
altitudeFn := func(localJD float64) float64 {
utJD := localJD - timezone/24.0
state := lite.MoonTopocentric(utJD, lon, lat, height)
altitude, _, _ := lite.HorizontalCoordinates(state.RightAscension, state.Declination, utJD, lon, lat)
utcJD := localJD - timezone/24.0
state := lite.MoonTopocentric(utcJD, lon, lat, height)
altitude, _, _ := lite.HorizontalCoordinates(state.RightAscension, state.Declination, utcJD, lon, lat)
residual := altitude + horizonDip
if aero {
residual += basic.RefractionFromTrueAltitude(altitude, 1010, 10)
@@ -149,7 +160,7 @@ func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (t
return time.Time{}, err
}
}
return basic.JDE2DateByZone(eventJD, date.Location(), true), nil
return basic.JD2DateByZone(eventJD-timezone/24, date.Location(), false), nil
}
func liteMoonSemidiameterDegrees(distanceEarthRadii float64) float64 {
+1 -1
View File
@@ -156,7 +156,7 @@ func TestHorizontalEntriesMatchDuplicatedEvaluation(t *testing.T) {
}
for _, s := range samples {
jd := basic.Date2JDE(s.date.UTC())
jd := basic.Date2JD(s.date.UTC())
altitude, azimuth, hourAngle := lite.HorizontalCoordinates(ApparentRa(s.date, s.lon, s.lat), ApparentDec(s.date, s.lon, s.lat), jd, s.lon, s.lat)
checks := []struct {
name string
+1 -1
View File
@@ -60,7 +60,7 @@ func BenchmarkMoonZenith(b *testing.B) {
func BenchmarkMoonHorizontalLegacy(b *testing.B) {
date, lon, lat := benchmarkHorizontalInputs()
jd := basic.Date2JDE(date.UTC())
jd := basic.Date2JD(date.UTC())
entries := []struct {
name string
pick func(altitude, azimuth, hourAngle float64) float64
+29 -18
View File
@@ -1,6 +1,7 @@
package sun
import (
"b612.me/astro/internal/civiltime"
"errors"
"math"
"time"
@@ -16,68 +17,68 @@ var (
// TrueLo 轻量真黄经 / lightweight true ecliptic longitude.
func TrueLo(date time.Time) float64 {
return lite.SunTrueLo(basic.Date2JDE(date.UTC()))
return lite.SunTrueLo(basic.Date2JD(date.UTC()))
}
// ApparentLo 轻量视黄经 / lightweight apparent ecliptic longitude.
func ApparentLo(date time.Time) float64 {
return lite.SunApparentLo(basic.Date2JDE(date.UTC()))
return lite.SunApparentLo(basic.Date2JD(date.UTC()))
}
// Distance 轻量日地距离 / lightweight Sun-Earth distance in AU.
func Distance(date time.Time) float64 {
return lite.SunDistanceAU(basic.Date2JDE(date.UTC()))
return lite.SunDistanceAU(basic.Date2JD(date.UTC()))
}
// TrueRa 轻量真赤经 / lightweight true right ascension.
func TrueRa(date time.Time) float64 {
ra, _ := lite.SunTrueRaDec(basic.Date2JDE(date.UTC()))
ra, _ := lite.SunTrueRaDec(basic.Date2JD(date.UTC()))
return ra
}
// TrueDec 轻量真赤纬 / lightweight true declination.
func TrueDec(date time.Time) float64 {
_, dec := lite.SunTrueRaDec(basic.Date2JDE(date.UTC()))
_, dec := lite.SunTrueRaDec(basic.Date2JD(date.UTC()))
return dec
}
// TrueRaDec 轻量真赤经、真赤纬 / lightweight true right ascension and declination.
func TrueRaDec(date time.Time) (float64, float64) {
return lite.SunTrueRaDec(basic.Date2JDE(date.UTC()))
return lite.SunTrueRaDec(basic.Date2JD(date.UTC()))
}
// ApparentRa 轻量视赤经 / lightweight apparent right ascension.
func ApparentRa(date time.Time) float64 {
ra, _ := lite.SunApparentRaDec(basic.Date2JDE(date.UTC()))
ra, _ := lite.SunApparentRaDec(basic.Date2JD(date.UTC()))
return ra
}
// ApparentDec 轻量视赤纬 / lightweight apparent declination.
func ApparentDec(date time.Time) float64 {
_, dec := lite.SunApparentRaDec(basic.Date2JDE(date.UTC()))
_, dec := lite.SunApparentRaDec(basic.Date2JD(date.UTC()))
return dec
}
// ApparentRaDec 轻量视赤经、视赤纬 / lightweight apparent right ascension and declination.
func ApparentRaDec(date time.Time) (float64, float64) {
return lite.SunApparentRaDec(basic.Date2JDE(date.UTC()))
return lite.SunApparentRaDec(basic.Date2JD(date.UTC()))
}
// HourAngle 轻量时角 / lightweight hour angle.
func HourAngle(date time.Time, lon, lat float64) float64 {
_, _, hourAngle := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JDE(date.UTC()), lon, lat)
_, _, hourAngle := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JD(date.UTC()), lon, lat)
return hourAngle
}
// Azimuth 轻量方位角 / lightweight azimuth.
func Azimuth(date time.Time, lon, lat float64) float64 {
_, azimuth, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JDE(date.UTC()), lon, lat)
_, azimuth, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JD(date.UTC()), lon, lat)
return azimuth
}
// Altitude 轻量高度角 / lightweight altitude.
func Altitude(date time.Time, lon, lat float64) float64 {
altitude, _, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JDE(date.UTC()), lon, lat)
altitude, _, _ := lite.HorizontalCoordinates(ApparentRa(date), ApparentDec(date), basic.Date2JD(date.UTC()), lon, lat)
return altitude
}
@@ -88,30 +89,40 @@ func Zenith(date time.Time, lon, lat float64) float64 {
// RiseTime 轻量日出时刻 / lightweight sunrise time.
func RiseTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
if result, err, handled := civiltime.Event(date, basic.ErrNotOnThisDate, func(d time.Time) (time.Time, error) {
return RiseTime(d, lon, lat, height, aero)
}); handled {
return result, err
}
return riseSetTime(date, lon, lat, height, aero, true)
}
// SetTime 轻量日落时刻 / lightweight sunset time.
func SetTime(date time.Time, lon, lat, height float64, aero bool) (time.Time, error) {
if result, err, handled := civiltime.Event(date, basic.ErrNotOnThisDate, func(d time.Time) (time.Time, error) {
return SetTime(d, lon, lat, height, aero)
}); handled {
return result, err
}
return riseSetTime(date, lon, lat, height, aero, false)
}
func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (time.Time, error) {
localMidnight := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
localJD := basic.Date2JDE(localMidnight)
localJD := basic.Date2JD(localMidnight)
_, offset := localMidnight.Zone()
timezone := float64(offset) / 3600.0
horizonDip := basic.HeightDegreeByLat(height, lat)
altitudeFn := func(localJD float64) float64 {
utJD := localJD - timezone/24.0
ra, dec := lite.SunApparentRaDec(utJD)
altitude, _, _ := lite.HorizontalCoordinates(ra, dec, utJD, lon, lat)
utcJD := localJD - timezone/24.0
ra, dec := lite.SunApparentRaDec(utcJD)
altitude, _, _ := lite.HorizontalCoordinates(ra, dec, utcJD, lon, lat)
residual := altitude + horizonDip
if aero {
residual += basic.RefractionFromTrueAltitude(altitude, 1010, 10)
residual += liteSunSemidiameterDegrees(lite.SunDistanceAU(utJD))
residual += liteSunSemidiameterDegrees(lite.SunDistanceAU(utcJD))
}
return residual
}
@@ -127,7 +138,7 @@ func riseSetTime(date time.Time, lon, lat, height float64, aero, isRise bool) (t
return time.Time{}, err
}
}
return basic.JDE2DateByZone(eventJD, date.Location(), true), nil
return basic.JD2DateByZone(eventJD-timezone/24, date.Location(), false), nil
}
func liteSunSemidiameterDegrees(distanceAU float64) float64 {