feat: 完善时标与天象几何计算并扩展输出接口
- 新增时标、ΔT 模型、质心时间与 UT1 支持 - 改进日月食、月掩、行星事件及路径边界计算 - 完善恒星三维自行与动态距离传播 - 扩展 SVG、GeoJSON、KML 输出与底层距离换算工具 - 整理中英文手册、示例资源及回归测试
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package tools
|
||||
|
||||
import "math"
|
||||
|
||||
// DistanceUnit 距离输入单位 / a unit accepted for distance input.
|
||||
type DistanceUnit uint8
|
||||
|
||||
const (
|
||||
// DistanceParsec 秒差距 / parsec.
|
||||
DistanceParsec DistanceUnit = iota
|
||||
// DistanceLightYear 光年 / light-year.
|
||||
DistanceLightYear
|
||||
// DistanceAU 天文单位 / astronomical unit.
|
||||
DistanceAU
|
||||
)
|
||||
|
||||
// 天文单位与光年取 IAU 定义值,秒差距由精确关系 648000/π 天文单位导出。
|
||||
const (
|
||||
AstronomicalUnitKilometers = 149597870.7
|
||||
LightYearKilometers = 9460730472580.8
|
||||
parsecAU = 648000 / math.Pi
|
||||
)
|
||||
|
||||
// DistanceToParsecs 把给定单位的距离换算为秒差距 / converts a distance in the given unit to parsecs.
|
||||
//
|
||||
// 非正数、NaN 与未知单位返回 NaN。
|
||||
func DistanceToParsecs(value float64, unit DistanceUnit) float64 {
|
||||
if math.IsNaN(value) || math.IsInf(value, 0) || value <= 0 {
|
||||
return math.NaN()
|
||||
}
|
||||
switch unit {
|
||||
case DistanceParsec:
|
||||
return value
|
||||
case DistanceLightYear:
|
||||
return value * LightYearKilometers / AstronomicalUnitKilometers / parsecAU
|
||||
case DistanceAU:
|
||||
return value / parsecAU
|
||||
}
|
||||
return math.NaN()
|
||||
}
|
||||
Reference in New Issue
Block a user