feat: 引入可切换星历模型并扩展天象观测链路

- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算
- 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询
- 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出
- 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解
- 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤
- 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持
- 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理
- 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
This commit is contained in:
2026-10-15 23:54:15 +08:00
parent 16c62a97d5
commit 044f2f4381
674 changed files with 62983 additions and 8396 deletions
+77
View File
@@ -0,0 +1,77 @@
package ltp
import (
"math"
"sync"
)
// 分段 Chebyshev 缓存的覆盖与精度:最短周期项 157.87 年,200 年段 16 阶误差远小于 1e-12 rad。
const (
basisStart = -10200.0
basisSpan = 200.0
basisSegs = 102
basisDegree = 16
)
type basisSeg struct {
once sync.Once
// 6 个分量(x 的 3 个、z 的 3 个)各 basisDegree+1 个系数,c0 已减半。
c [6][basisDegree + 1]float64
}
var basisTable [basisSegs]basisSeg
// EclipticBasisExact 历元平黄道在 J2000 平赤道下的正交基:x 指向平春分点,z 为黄道极 / exact basis of the mean ecliptic of date.
func EclipticBasisExact(epj float64) (x, y, z Vector3) {
z = EclipticPole(epj)
x, _ = Normalize(Cross(EquatorPole(epj), z))
return x, Cross(z, x), z
}
// EclipticBasis 同 EclipticBasisExact,覆盖区间内用分段 Chebyshev 近似(差 < 1e-12 rad),区间外精确计算 / cached form of EclipticBasisExact.
func EclipticBasis(epj float64) (x, y, z Vector3) {
u := (epj - basisStart) / basisSpan
i := int(math.Floor(u))
if i < 0 || i >= basisSegs {
return EclipticBasisExact(epj)
}
seg := &basisTable[i]
seg.once.Do(func() { seg.fit(basisStart + float64(i)*basisSpan) })
s := 2*(u-float64(i)) - 1
var v [6]float64
for k := range v {
v[k] = clenshaw(&seg.c[k], s)
}
x = Vector3{v[0], v[1], v[2]}
z = Vector3{v[3], v[4], v[5]}
return x, Cross(z, x), z
}
func (seg *basisSeg) fit(start float64) {
const n = basisDegree + 1
var f [n][6]float64
for j := 0; j < n; j++ {
s := math.Cos(math.Pi * (float64(j) + 0.5) / n)
x, _, z := EclipticBasisExact(start + (s+1)/2*basisSpan)
f[j] = [6]float64{x[0], x[1], x[2], z[0], z[1], z[2]}
}
for k := 0; k < 6; k++ {
for m := 0; m < n; m++ {
sum := 0.0
for j := 0; j < n; j++ {
sum += f[j][k] * math.Cos(math.Pi*float64(m)*(float64(j)+0.5)/n)
}
seg.c[k][m] = 2 * sum / n
}
seg.c[k][0] /= 2
}
}
func clenshaw(c *[basisDegree + 1]float64, s float64) float64 {
b1, b2 := 0.0, 0.0
for m := basisDegree; m >= 1; m-- {
b1, b2 = 2*s*b1-b2+c[m], b1
}
return s*b1 - b2 + c[0]
}
+43
View File
@@ -0,0 +1,43 @@
// 被测契约:缓存基与精确基在覆盖区间内相差 < 1e-12,区间外逐位相同。
package ltp
import (
"math"
"testing"
)
func TestEclipticBasisMatchesExact(t *testing.T) {
worst := 0.0
for epj := -10199.9; epj < 10199.9; epj += 3.137 {
ax, ay, az := EclipticBasis(epj)
ex, ey, ez := EclipticBasisExact(epj)
for i := 0; i < 3; i++ {
worst = math.Max(worst, math.Abs(ax[i]-ex[i]))
worst = math.Max(worst, math.Abs(ay[i]-ey[i]))
worst = math.Max(worst, math.Abs(az[i]-ez[i]))
}
}
t.Logf("max component diff %.3g", worst)
if worst > 1e-12 {
t.Fatalf("cached basis differs by %.3g", worst)
}
for _, epj := range []float64{-10300, 10300} {
ax, _, az := EclipticBasis(epj)
ex, _, ez := EclipticBasisExact(epj)
if ax != ex || az != ez {
t.Fatalf("epj %v: outside the cache the exact basis must be used", epj)
}
}
}
func BenchmarkEclipticBasis(b *testing.B) {
for i := 0; i < b.N; i++ {
EclipticBasis(2000 + float64(i%7300)*0.27)
}
}
func BenchmarkEclipticBasisExact(b *testing.B) {
for i := 0; i < b.N; i++ {
EclipticBasisExact(2000 + float64(i%7300)*0.27)
}
}
+119
View File
@@ -0,0 +1,119 @@
// Package ltp 长期岁差的黄极与赤道极向量(J2000 平赤道坐标,±20 万年有效)。
package ltp
import "math"
const (
as2r = 4.848136811095359935899141e-6
d2pi = 6.283185307179586476925287
eps0 = 84381.406 * as2r
)
// Vector3 三维向量 / a 3-vector.
type Vector3 [3]float64
// EclipticPole 历元平黄道极 / mean ecliptic pole of epoch, epj in Julian years.
func EclipticPole(epj float64) Vector3 {
pqPol := [2][4]float64{
{+5851.607687, -0.1189000, -0.00028913, +0.000000101},
{-1600.886300, +1.1689818, -0.00000020, -0.000000437},
}
pqPer := [8][5]float64{
{708.15, -5486.751211, -684.661560, 667.666730, -5523.863691},
{2309.00, -17.127623, 2446.283880, -2354.886252, -549.747450},
{1620.00, -617.517403, 399.671049, -428.152441, -310.998056},
{492.20, 413.442940, -356.652376, 376.202861, 421.535876},
{1183.00, 78.614193, -186.387003, 184.778874, -36.776172},
{622.00, -180.732815, -316.800070, 335.321713, -145.278396},
{882.00, -87.676083, 198.296071, -185.138669, -34.744450},
{547.00, 46.140315, 101.135679, -120.972830, 22.885731},
}
t := (epj - 2000.0) / 100.0
p, q := 0.0, 0.0
for i := 0; i < 8; i++ {
w := d2pi * t
a := w / pqPer[i][0]
s := math.Sin(a)
c := math.Cos(a)
p += c*pqPer[i][1] + s*pqPer[i][3]
q += c*pqPer[i][2] + s*pqPer[i][4]
}
w := 1.0
for i := 0; i < 4; i++ {
p += pqPol[0][i] * w
q += pqPol[1][i] * w
w *= t
}
p *= as2r
q *= as2r
z := math.Sqrt(math.Max(1.0-p*p-q*q, 0.0))
s := math.Sin(eps0)
c := math.Cos(eps0)
return Vector3{p, -q*c - z*s, -q*s + z*c}
}
// EquatorPole 历元平赤道极 / mean equator pole of epoch, epj in Julian years.
func EquatorPole(epj float64) Vector3 {
xyPol := [2][4]float64{
{+5453.282155, +0.4252841, -0.00037173, -0.000000152},
{-73750.930350, -0.7675452, -0.00018725, +0.000000231},
}
xyPer := [14][5]float64{
{256.75, -819.940624, 75004.344875, 81491.287984, 1558.515853},
{708.15, -8444.676815, 624.033993, 787.163481, 7774.939698},
{274.20, 2600.009459, 1251.136893, 1251.296102, -2219.534038},
{241.45, 2755.175630, -1102.212834, -1257.950837, -2523.969396},
{2309.00, -167.659835, -2660.664980, -2966.799730, 247.850422},
{492.20, 871.855056, 699.291817, 639.744522, -846.485643},
{396.10, 44.769698, 153.167220, 131.600209, -1393.124055},
{288.90, -512.313065, -950.865637, -445.040117, 368.526116},
{231.10, -819.415595, 499.754645, 584.522874, 749.045012},
{1610.00, -538.071099, -145.188210, -89.756563, 444.704518},
{620.00, -189.793622, 558.116553, 524.429630, 235.934465},
{157.87, -402.922932, -23.923029, -13.549067, 374.049623},
{220.30, 179.516345, -165.405086, -210.157124, -171.330180},
{1200.00, -9.814756, 9.344131, -44.919798, -22.899655},
}
t := (epj - 2000.0) / 100.0
x, y := 0.0, 0.0
for i := 0; i < 14; i++ {
w := d2pi * t
a := w / xyPer[i][0]
s := math.Sin(a)
c := math.Cos(a)
x += c*xyPer[i][1] + s*xyPer[i][3]
y += c*xyPer[i][2] + s*xyPer[i][4]
}
w := 1.0
for i := 0; i < 4; i++ {
x += xyPol[0][i] * w
y += xyPol[1][i] * w
w *= t
}
x *= as2r
y *= as2r
w = x*x + y*y
z := 0.0
if w < 1.0 {
z = math.Sqrt(1.0 - w)
}
return Vector3{x, y, z}
}
// Cross 叉乘 / cross product.
func Cross(a, b Vector3) Vector3 {
return Vector3{
a[1]*b[2] - a[2]*b[1],
a[2]*b[0] - a[0]*b[2],
a[0]*b[1] - a[1]*b[0],
}
}
// Normalize 单位向量与原模长,零向量返回零 / unit vector and norm; zero stays zero.
func Normalize(p Vector3) (Vector3, float64) {
w := math.Sqrt(p[0]*p[0] + p[1]*p[1] + p[2]*p[2])
if w == 0.0 {
return Vector3{0, 0, 0}, 0
}
return Vector3{p[0] / w, p[1] / w, p[2] / w}, w
}