Files
astro/eclipse/svg/lunar_model.go
T
b612 044f2f4381 feat: 引入可切换星历模型并扩展天象观测链路
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算
- 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询
- 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出
- 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解
- 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤
- 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持
- 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理
- 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
2026-10-15 23:54:15 +08:00

162 lines
4.9 KiB
Go

package svg
import (
"math"
"time"
"b612.me/astro"
"b612.me/astro/basic"
eclipsecore "b612.me/astro/eclipse"
)
type LunarEclipseType = eclipsecore.LunarEclipseType
type LunarEclipseContactPoint = eclipsecore.LunarEclipseContactPoint
type LunarEclipseInfo = eclipsecore.LunarEclipseInfo
const (
LunarEclipseNone = eclipsecore.LunarEclipseNone
LunarEclipsePenumbral = eclipsecore.LunarEclipsePenumbral
LunarEclipsePartial = eclipsecore.LunarEclipsePartial
LunarEclipseTotal = eclipsecore.LunarEclipseTotal
)
func lunarEclipseInfoFromBasic(
result basic.LunarEclipseResult,
location *time.Location,
) LunarEclipseInfo {
info := LunarEclipseInfo{
Type: mapBasicLunarEclipseType(result.Type),
LunarLimbApplied: result.LunarLimbApplied,
PenumbralMagnitude: result.PenumbralMagnitude,
UmbralMagnitude: result.Magnitude,
PenumbralStart: ttJDEToTime(result.PenumbralStart, location),
PartialStart: ttJDEToTime(result.PartialStart, location),
TotalStart: ttJDEToTime(result.TotalStart, location),
Maximum: ttJDEToTime(result.Maximum, location),
TotalEnd: ttJDEToTime(result.TotalEnd, location),
PartialEnd: ttJDEToTime(result.PartialEnd, location),
PenumbralEnd: ttJDEToTime(result.PenumbralEnd, location),
ContactPoints: lunarEclipseContactPointsFromBasic(result, location),
HasPenumbral: result.HasPenumbral,
HasPartial: result.HasPartial,
HasTotal: result.HasTotal,
}
return info
}
// lunarEclipseDisplayInfo 给出写图用的时刻副本;几何必须用未换算的 UTC 时刻,
// 否则把 UT1 读数当民用时刻会平移地平线、月下点与地心坐标块。
func lunarEclipseDisplayInfo(info LunarEclipseInfo, scale astro.TimeScale) LunarEclipseInfo {
if scale == astro.TimeScaleUT1 {
return eclipsecore.LunarEclipseInfoInUT1(info)
}
return info
}
func lunarEclipseContactPointsFromBasic(
result basic.LunarEclipseResult,
location *time.Location,
) []LunarEclipseContactPoint {
if !result.HasPenumbral {
return nil
}
contacts := []LunarEclipseContactPoint{
lunarEclipseContactPoint("P1", result.PenumbralStart, location, false),
}
if result.HasPartial {
contacts = append(contacts, lunarEclipseContactPoint("U1", result.PartialStart, location, false))
}
if result.HasTotal {
contacts = append(contacts, lunarEclipseContactPoint("U2", result.TotalStart, location, true))
}
if result.HasTotal {
contacts = append(contacts, lunarEclipseContactPoint("U3", result.TotalEnd, location, true))
}
if result.HasPartial {
contacts = append(contacts, lunarEclipseContactPoint("U4", result.PartialEnd, location, false))
}
contacts = append(contacts, lunarEclipseContactPoint("P4", result.PenumbralEnd, location, false))
return contacts
}
func lunarEclipseContactPoint(
label string,
ttJDE float64,
location *time.Location,
internalContact bool,
) LunarEclipseContactPoint {
moonCenterPA := lunarEclipseMoonCenterPositionAngle(ttJDE)
shadowCenterPA := normalizeDegree360(moonCenterPA + 180)
contactPA := shadowCenterPA
if internalContact {
contactPA = moonCenterPA
}
return LunarEclipseContactPoint{
Label: label,
Time: ttJDEToTime(ttJDE, location),
ContactPositionAngle: contactPA,
ContactClockwiseAngle: normalizeDegree360(360 - contactPA),
MoonCenterPositionAngle: moonCenterPA,
ShadowCenterPositionAngle: shadowCenterPA,
}
}
func lunarEclipseMoonCenterPositionAngle(ttJDE float64) float64 {
shadowRA, shadowDec := lunarEclipseShadowCenterRaDec(ttJDE)
moonRA, moonDec := basic.HMoonTrueRaDec(ttJDE)
return lunarEclipsePositionAngle(shadowRA, shadowDec, moonRA, moonDec)
}
func lunarEclipseShadowCenterRaDec(ttJDE float64) (float64, float64) {
sunRA, sunDec := basic.HSunApparentRaDec(ttJDE)
return normalizeDegree360(sunRA + 180), -sunDec
}
func lunarEclipsePositionAngle(fromRA, fromDec, toRA, toDec float64) float64 {
dRA := (toRA - fromRA) * math.Pi / 180
fromDecRad := fromDec * math.Pi / 180
toDecRad := toDec * math.Pi / 180
angle := math.Atan2(
math.Sin(dRA),
math.Cos(fromDecRad)*math.Tan(toDecRad)-math.Sin(fromDecRad)*math.Cos(dRA),
) * 180 / math.Pi
return normalizeDegree360(angle)
}
func mapBasicLunarEclipseType(eclipseType basic.LunarEclipseType) LunarEclipseType {
switch eclipseType {
case basic.LunarEclipsePenumbral:
return LunarEclipsePenumbral
case basic.LunarEclipsePartial:
return LunarEclipsePartial
case basic.LunarEclipseTotal:
return LunarEclipseTotal
default:
return LunarEclipseNone
}
}
func ttJDEToTime(ttJDE float64, location *time.Location) time.Time {
if ttJDE == 0 {
return time.Time{}
}
utcJD := basic.TT2UTC(ttJDE)
return basic.JD2DateByZone(utcJD, location, false)
}
func timeToTTJDE(date time.Time) float64 {
utcJD := basic.Date2JD(date.UTC())
return basic.UTC2TT(utcJD)
}
func normalizeDegree360(angle float64) float64 {
angle = math.Mod(angle, 360)
if angle < 0 {
angle += 360
}
return angle
}