044f2f4381
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算 - 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询 - 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出 - 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解 - 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤 - 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持 - 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理 - 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
237 lines
8.1 KiB
Go
237 lines
8.1 KiB
Go
package basic
|
|
|
|
import (
|
|
"math"
|
|
|
|
. "b612.me/astro/tools"
|
|
)
|
|
|
|
// OrbitMeanMotion 返回历元平均角速度,单位度/日。
|
|
// 对近日点形式的抛物/双曲轨道返回 NaN。
|
|
func OrbitMeanMotion(elements OrbitElements) float64 {
|
|
if elements.usesPerihelionForm() {
|
|
if !elements.validPerihelionForm() || elements.E >= 1 {
|
|
return math.NaN()
|
|
}
|
|
semiMajorAxis := elements.Q / (1 - elements.E)
|
|
if !isFinitePositive(semiMajorAxis) {
|
|
return math.NaN()
|
|
}
|
|
if isFinite(elements.MDot) && elements.MDot != 0 {
|
|
return elements.MDot
|
|
}
|
|
return gaussianGravitationalConstant / math.Pow(semiMajorAxis, 1.5) * deg
|
|
}
|
|
if !elements.validEllipticClassical() {
|
|
return math.NaN()
|
|
}
|
|
if isFinite(elements.MDot) && elements.MDot != 0 {
|
|
return elements.MDot
|
|
}
|
|
return gaussianGravitationalConstant / math.Pow(elements.A, 1.5) * deg
|
|
}
|
|
|
|
// OrbitMeanAnomaly 返回给定 TT/TDB 儒略日的平近点角,单位度。
|
|
// 对抛物/双曲轨道返回 NaN。
|
|
func OrbitMeanAnomaly(jd float64, elements OrbitElements) float64 {
|
|
meanAnomalyDeg, ok := orbitMeanAnomalyDegAt(jd, elements)
|
|
if !ok {
|
|
return math.NaN()
|
|
}
|
|
return Limit360(meanAnomalyDeg)
|
|
}
|
|
|
|
// OrbitEccentricAnomaly 返回给定 TT/TDB 儒略日的偏近点角,单位度。
|
|
// 仅适用于椭圆轨道;对抛物/双曲轨道返回 NaN。
|
|
func OrbitEccentricAnomaly(jd float64, elements OrbitElements) float64 {
|
|
resolved := orbitElementsAt(jd, elements)
|
|
meanAnomalyDeg, ok := orbitMeanAnomalyDegAt(jd, elements)
|
|
if !ok || !resolved.validEllipticClassical() && !(resolved.validPerihelionForm() && resolved.E < 1) {
|
|
return math.NaN()
|
|
}
|
|
eccentricAnomaly, ok := orbitEccentricAnomalyRad(meanAnomalyDeg*rad, resolved.E)
|
|
if !ok {
|
|
return math.NaN()
|
|
}
|
|
return Limit360(eccentricAnomaly * deg)
|
|
}
|
|
|
|
// OrbitTrueAnomaly 返回给定 TT/TDB 儒略日的真近点角,单位度。
|
|
func OrbitTrueAnomaly(jde float64, elements OrbitElements) float64 {
|
|
trueAnomaly, _, _, ok := orbitTrueAnomalyAndRadius(jde, elements)
|
|
if !ok {
|
|
return math.NaN()
|
|
}
|
|
return Limit360(trueAnomaly * deg)
|
|
}
|
|
|
|
func orbitMeanAnomalyDegAt(jd float64, elements OrbitElements) (float64, bool) {
|
|
if !isFinite(jd) {
|
|
return math.NaN(), false
|
|
}
|
|
if elements.usesPerihelionForm() {
|
|
if !elements.validPerihelionForm() || elements.E >= 1 {
|
|
return math.NaN(), false
|
|
}
|
|
semiMajorAxis := elements.Q / (1 - elements.E)
|
|
if !isFinitePositive(semiMajorAxis) {
|
|
return math.NaN(), false
|
|
}
|
|
meanMotion := elements.MDot
|
|
if !isFinite(meanMotion) || meanMotion == 0 {
|
|
meanMotion = gaussianGravitationalConstant / math.Pow(semiMajorAxis, 1.5) * deg
|
|
}
|
|
return meanMotion * (jd - elements.TpJD), true
|
|
}
|
|
|
|
resolved := orbitElementsAt(jd, elements)
|
|
if !resolved.validEllipticClassical() {
|
|
return math.NaN(), false
|
|
}
|
|
if isFinite(elements.MDot) && elements.MDot != 0 {
|
|
return elements.M0 + elements.MDot*(jd-elements.EpochJD), true
|
|
}
|
|
meanMotion := gaussianGravitationalConstant / math.Pow(resolved.A, 1.5) * deg
|
|
return resolved.M0 + meanMotion*(jd-elements.EpochJD), true
|
|
}
|
|
|
|
func orbitEccentricAnomalyRad(meanAnomalyRad, eccentricity float64) (float64, bool) {
|
|
if !isFinite(meanAnomalyRad) || !isFinite(eccentricity) || eccentricity < 0 || eccentricity >= 1 {
|
|
return math.NaN(), false
|
|
}
|
|
if meanAnomalyRad > math.Pi {
|
|
meanAnomalyRad -= 2 * math.Pi
|
|
} else if meanAnomalyRad < -math.Pi {
|
|
meanAnomalyRad += 2 * math.Pi
|
|
}
|
|
|
|
eccentricAnomaly := meanAnomalyRad
|
|
if eccentricity >= 0.8 {
|
|
eccentricAnomaly = math.Pi
|
|
if meanAnomalyRad < 0 {
|
|
eccentricAnomaly = -math.Pi
|
|
}
|
|
}
|
|
|
|
for i := 0; i < 32; i++ {
|
|
sinE, cosE := math.Sincos(eccentricAnomaly)
|
|
delta := (eccentricAnomaly - eccentricity*sinE - meanAnomalyRad) / (1 - eccentricity*cosE)
|
|
eccentricAnomaly -= delta
|
|
if math.Abs(delta) < 1e-14 {
|
|
return eccentricAnomaly, true
|
|
}
|
|
}
|
|
return eccentricAnomaly, true
|
|
}
|
|
|
|
func orbitHyperbolicAnomaly(meanAnomaly, eccentricity float64) (float64, bool) {
|
|
if !isFinite(meanAnomaly) || !isFinite(eccentricity) || eccentricity <= 1 {
|
|
return math.NaN(), false
|
|
}
|
|
|
|
hyperbolicAnomaly := math.Asinh(meanAnomaly / eccentricity)
|
|
if hyperbolicAnomaly == 0 && meanAnomaly != 0 {
|
|
hyperbolicAnomaly = math.Log(2*math.Abs(meanAnomaly)/eccentricity + 1.8)
|
|
if meanAnomaly < 0 {
|
|
hyperbolicAnomaly = -hyperbolicAnomaly
|
|
}
|
|
}
|
|
|
|
for i := 0; i < 32; i++ {
|
|
sinhH := math.Sinh(hyperbolicAnomaly)
|
|
coshH := math.Cosh(hyperbolicAnomaly)
|
|
delta := (eccentricity*sinhH - hyperbolicAnomaly - meanAnomaly) / (eccentricity*coshH - 1)
|
|
hyperbolicAnomaly -= delta
|
|
if math.Abs(delta) < 1e-14 {
|
|
return hyperbolicAnomaly, true
|
|
}
|
|
}
|
|
return hyperbolicAnomaly, true
|
|
}
|
|
|
|
func orbitTrueAnomalyAndRadius(jde float64, elements OrbitElements) (trueAnomaly, radius float64, resolved OrbitElements, ok bool) {
|
|
resolved = orbitElementsAt(jde, elements)
|
|
if resolved.usesPerihelionForm() {
|
|
if !resolved.validPerihelionForm() {
|
|
return math.NaN(), math.NaN(), resolved, false
|
|
}
|
|
switch {
|
|
case math.Abs(resolved.E-1) <= orbitParabolicTolerance:
|
|
return orbitParabolicTrueAnomalyAndRadius(jde, resolved)
|
|
case resolved.E < 1:
|
|
return orbitEllipticTrueAnomalyAndRadiusFromPerihelion(jde, resolved)
|
|
default:
|
|
return orbitHyperbolicTrueAnomalyAndRadius(jde, resolved)
|
|
}
|
|
}
|
|
if !resolved.validEllipticClassical() {
|
|
return math.NaN(), math.NaN(), resolved, false
|
|
}
|
|
meanAnomalyDeg, ok := orbitMeanAnomalyDegAt(jde, elements)
|
|
if !ok {
|
|
return math.NaN(), math.NaN(), resolved, false
|
|
}
|
|
trueAnomaly, radius, ok = orbitEllipticTrueAnomalyAndRadius(meanAnomalyDeg*rad, resolved.A, resolved.E)
|
|
return trueAnomaly, radius, resolved, ok
|
|
}
|
|
|
|
func orbitEllipticTrueAnomalyAndRadiusFromPerihelion(jd float64, elements OrbitElements) (trueAnomaly, radius float64, resolved OrbitElements, ok bool) {
|
|
semiMajorAxis := elements.Q / (1 - elements.E)
|
|
if !isFinitePositive(semiMajorAxis) {
|
|
return math.NaN(), math.NaN(), elements, false
|
|
}
|
|
meanAnomalyDeg, ok := orbitMeanAnomalyDegAt(jd, elements)
|
|
if !ok {
|
|
return math.NaN(), math.NaN(), elements, false
|
|
}
|
|
trueAnomaly, radius, ok = orbitEllipticTrueAnomalyAndRadius(meanAnomalyDeg*rad, semiMajorAxis, elements.E)
|
|
if !ok {
|
|
return math.NaN(), math.NaN(), elements, false
|
|
}
|
|
resolved = elements
|
|
resolved.A = semiMajorAxis
|
|
return trueAnomaly, radius, resolved, true
|
|
}
|
|
|
|
func orbitEllipticTrueAnomalyAndRadius(meanAnomalyRad, semiMajorAxis, eccentricity float64) (float64, float64, bool) {
|
|
eccentricAnomaly, ok := orbitEccentricAnomalyRad(meanAnomalyRad, eccentricity)
|
|
if !ok {
|
|
return math.NaN(), math.NaN(), false
|
|
}
|
|
sinE, cosE := math.Sincos(eccentricAnomaly)
|
|
radius := semiMajorAxis * (1 - eccentricity*cosE)
|
|
trueAnomaly := math.Atan2(math.Sqrt(1-eccentricity*eccentricity)*sinE, cosE-eccentricity)
|
|
return trueAnomaly, radius, true
|
|
}
|
|
|
|
func orbitParabolicTrueAnomalyAndRadius(jd float64, elements OrbitElements) (trueAnomaly, radius float64, resolved OrbitElements, ok bool) {
|
|
if !isFinitePositive(elements.Q) || !isFinite(elements.TpJD) {
|
|
return math.NaN(), math.NaN(), elements, false
|
|
}
|
|
w := 1.5 * gaussianGravitationalConstant * (jd - elements.TpJD) / (math.Sqrt2 * math.Pow(elements.Q, 1.5))
|
|
// tan(v/2) 是 w 的奇函数;按 |w| 求再补符号,避免 w 很负时 w+sqrt(w²+1) 相消为 0。
|
|
y := math.Cbrt(math.Abs(w) + math.Sqrt(w*w+1))
|
|
d := math.Copysign(y-1/y, w)
|
|
trueAnomaly = 2 * math.Atan(d)
|
|
radius = elements.Q * (1 + d*d)
|
|
resolved = elements
|
|
return trueAnomaly, radius, resolved, true
|
|
}
|
|
|
|
func orbitHyperbolicTrueAnomalyAndRadius(jd float64, elements OrbitElements) (trueAnomaly, radius float64, resolved OrbitElements, ok bool) {
|
|
if !isFinitePositive(elements.Q) || !isFinite(elements.TpJD) || !isFinite(elements.E) || elements.E <= 1 {
|
|
return math.NaN(), math.NaN(), elements, false
|
|
}
|
|
semiMajorAxis := elements.Q / (elements.E - 1)
|
|
meanAnomaly := gaussianGravitationalConstant * (jd - elements.TpJD) / math.Pow(semiMajorAxis, 1.5)
|
|
hyperbolicAnomaly, ok := orbitHyperbolicAnomaly(meanAnomaly, elements.E)
|
|
if !ok {
|
|
return math.NaN(), math.NaN(), elements, false
|
|
}
|
|
radius = semiMajorAxis * (elements.E*math.Cosh(hyperbolicAnomaly) - 1)
|
|
trueAnomaly = 2 * math.Atan(math.Sqrt((elements.E+1)/(elements.E-1))*math.Tanh(hyperbolicAnomaly/2))
|
|
resolved = elements
|
|
resolved.A = -semiMajorAxis
|
|
return trueAnomaly, radius, resolved, true
|
|
}
|