Files
astro/basic/solar_terms.go
T
b612 2bf8478639 feat: 完善日月食与月掩几何链路并扩展历法接口
- 新增日月食中心带、偏食带、阴影足迹、等时线、食分线及升落边界计算,支持极区与混合食拓扑
- 新增日食单时刻阴影求解器、站心状态查询、批量采样和 ΔT 覆盖接口
- 重构恒星与行星月掩路径,补充有限盘面接触、站心修正、掩带宽度、极区投影及升落边界
- 扩展 SVG 与 GeoJSON 输出,支持详细面板、全球/极区/地球投影、边界闭合、时间标记和拓扑签名
- 扩展日月食候选搜索、局地搜索、沙罗序列预计算与范围外推,补充系列锚点和成员一致性校验
- 补齐古历纪年、儒略历独有闰日、多公历候选、历法改革跨日及精确日期运算接口
- 优化 ΔT、章动、恒星时、月球地平线、事件根搜索和本地星历缓存,降低重复计算开销并提升边界稳定
2026-09-17 12:27:40 +08:00

118 lines
3.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package basic
import "math"
func GetMoonLoops(year float64, loop int) []float64 {
var start float64
var newMoon, lastNewMoon float64
moonLoops := make([]float64, loop)
if year < 6000 {
start = year + 11.00/12.00 + 5.00/30.00/12.00
} else {
start = year + 9.00/12.00 + 5.00/30.00/12.00
}
i := 1
for j := 0; j < loop; j++ {
if year > 3000 {
newMoon = TD2UT(CalcMoonSH(start+float64(i-1)/12.5, 0)+8.0/24.0, false)
} else {
newMoon = TD2UT(CalcMoonS(start+float64(i-1)/12.5, 0)+8.0/24.0, false)
}
if i != 1 {
if newMoon == lastNewMoon {
j--
i++
continue
}
}
moonLoops[j] = newMoon
lastNewMoon = moonLoops[j]
i++
}
return moonLoops
}
// GetJieqiLoops 返回从该年冬至起连续 loop 个节气时刻(北京时间,按 15° 一步):
// 每 24 个节气跨一年,loop<=0 返回 nil;黄经一律归化到 (0, 360],
// 因此 loop 超过 31 时也不会把 >360° 的角度丢给 GetJQTime(那里会静默 NaN)。
// GetJieqiLoops returns loop consecutive solar-term instants starting at the winter solstice of
// year; 24 terms span one year. Non-positive loop returns nil, and the longitude is normalised into
// (0, 360] so loops beyond 31 never hand an out-of-range angle to GetJQTime.
func GetJieqiLoops(year, loop int) []float64 {
if loop <= 0 {
return nil
}
start := 270
jq := make([]float64, loop)
for i := 1; i <= loop; i++ {
angle := start + 15*(i-1)
for angle > 360 {
angle -= 360
}
jq[i-1] = GetJQTime(year+int(math.Ceil(float64(i-1)/24.000)), angle) + 8.0/24.0
}
return jq
}
func GetJQTime(year, angle int) float64 {
// Calculate initial day based on angle parity
var initialDay float64
if angle%2 == 0 {
initialDay = 18
} else {
initialDay = 3
}
// Calculate temporary factor for month offset
var tempFactor float64
if angle%10 != 0 {
tempFactor = float64(angle+15) / 30.0
} else {
tempFactor = float64(angle) / 30.0
}
// Calculate initial month, adjusting if超过 12
initialMonth := 3.0 + tempFactor
if initialMonth > 12.0 {
initialMonth -= 12.0
}
// Calculate initial Julian date
initialJD := JDECalc(year, int(initialMonth), initialDay)
// Set target angle for iteration; if angle is 0, use 360
targetAngle := float64(angle)
if angle == 0 {
targetAngle = 360.0
}
// Newton-Raphson iteration to find precise Julian date
currentJD := initialJD
var ok bool
currentJD, ok = eventNewtonRefine(currentJD, 0.00001, func(previousJD float64) float64 {
errorValue := JQLospec(previousJD, targetAngle) - targetAngle
derivative := (JQLospec(previousJD+0.000005, targetAngle) - JQLospec(previousJD-0.000005, targetAngle)) / 0.00001
return errorValue / derivative
})
if !ok {
return math.NaN()
}
// Convert to UT and return
return TD2UT(currentJD, false)
}
func JQLospec(jd float64, target float64) float64 {
sunLo := HSunApparentLo(jd)
if target >= 345 {
if sunLo <= 12 {
sunLo += 360
}
} else if target <= 15 {
if sunLo >= 350 {
sunLo -= 360
}
}
return sunLo
}