044f2f4381
- 新增半解析、旧模型、自定义与多源堆叠星历实例,提供 Context、Instance、SPK 读取及状态与视位置计算 - 统一太阳、月球和行星实例接口,扩展黄经穿越、留、相位、最近角距、偕日可见、任意高度升落、轨道节点及凌日等天象查询 - 完善日月食、月掩与凌日的月缘剖面、有限盘面接触、站心修正、局地可见性、全球路径和地图输出 - 新增 SVG、GeoJSON、KML 天象输出及凌日、月掩和月缘地形相关缓存与几何求解 - 新增恒星星表导入与查询,支持 CSV、Hipparcos、BSC5、Stellarium 等格式及名称、交叉标识、锥面检索和星等过滤 - 补充 IAU 2006、地球定向、折射消光、大气观测、轨道传播及半解析行星/月球数据支持 - 将默认未来民用时标切换为 TimeScaleLeapHour,更新 2027–2400 农历速查表、中文日期解析和时区边界处理 - 增加事件基线、跨模型回归、几何边界、月缘地形和输出契约测试,完善中英文手册、示例资源、NOTICE 与忽略规则
113 lines
4.1 KiB
Go
113 lines
4.1 KiB
Go
package basic
|
|
|
|
import (
|
|
"math"
|
|
|
|
. "b612.me/astro/tools"
|
|
)
|
|
|
|
type planetGeocentricPosition struct {
|
|
x float64
|
|
y float64
|
|
z float64
|
|
lo float64
|
|
bo float64
|
|
}
|
|
|
|
func planetHeliocentricXYZN(planetIndex int, jde float64, n int, instances ...*Instance) (float64, float64, float64) {
|
|
inst := instanceValue(instances)
|
|
|
|
l := PlanetCoordinateNWithInstance(planetIndex, 0, jde, n, inst)
|
|
b := PlanetCoordinateNWithInstance(planetIndex, 1, jde, n, inst)
|
|
r := PlanetCoordinateNWithInstance(planetIndex, 2, jde, n, inst)
|
|
return sphericalToRectangular(l, b, r)
|
|
}
|
|
|
|
func earthHeliocentricXYZN(jde float64, n int, instances ...*Instance) (float64, float64, float64) {
|
|
inst := instanceValue(instances)
|
|
|
|
l := PlanetCoordinateNWithInstance(-1, 0, jde, n, inst)
|
|
b := PlanetCoordinateNWithInstance(-1, 1, jde, n, inst)
|
|
r := PlanetCoordinateNWithInstance(-1, 2, jde, n, inst)
|
|
return sphericalToRectangular(l, b, r)
|
|
}
|
|
|
|
func sphericalToRectangular(lo, bo, radius float64) (float64, float64, float64) {
|
|
cosBo := math.Cos(bo * math.Pi / 180)
|
|
return radius * cosBo * math.Cos(lo*math.Pi/180),
|
|
radius * cosBo * math.Sin(lo*math.Pi/180),
|
|
radius * math.Sin(bo*math.Pi/180)
|
|
}
|
|
|
|
func geocentricPositionFromRectangular(x, y, z float64) planetGeocentricPosition {
|
|
lo := math.Atan2(y, x) * 180 / math.Pi
|
|
bo := math.Atan2(z, math.Sqrt(x*x+y*y)) * 180 / math.Pi
|
|
return planetGeocentricPosition{
|
|
x: x,
|
|
y: y,
|
|
z: z,
|
|
lo: Limit360(lo),
|
|
bo: bo,
|
|
}
|
|
}
|
|
|
|
func planetGeocentricPositionN(planetIndex int, planetJD, earthJDE float64, n int) planetGeocentricPosition {
|
|
px, py, pz := planetHeliocentricXYZN(planetIndex, planetJD, n)
|
|
ex, ey, ez := earthHeliocentricXYZN(earthJDE, n)
|
|
return geocentricPositionFromRectangular(px-ex, py-ey, pz-ez)
|
|
}
|
|
|
|
func planetGeocentricPositionWithEarthN(planetIndex int, planetJD float64, ex, ey, ez float64, n int, instances ...*Instance) planetGeocentricPosition {
|
|
inst := instanceValue(instances)
|
|
|
|
px, py, pz := planetHeliocentricXYZN(planetIndex, planetJD, n, inst)
|
|
return geocentricPositionFromRectangular(px-ex, py-ey, pz-ez)
|
|
}
|
|
|
|
func planetApparentGeocentricPositionN(planetIndex int, jd float64, n int) (planetGeocentricPosition, float64) {
|
|
geo, tau, _ := planetApparentGeocentricPositionAndDistanceN(planetIndex, jd, n)
|
|
return geo, tau
|
|
}
|
|
|
|
func planetApparentGeocentricPositionAndDistanceN(
|
|
planetIndex int,
|
|
jde float64,
|
|
n int, instances ...*Instance) (planetGeocentricPosition, float64, float64) {
|
|
inst := instanceValue(instances)
|
|
|
|
if planetIndex >= 1 && planetIndex <= 7 {
|
|
if lo, bo, tau, dist, ok := boundVectorApparent(planetBody[planetIndex], jde, n, inst); ok {
|
|
x, y, z := sphericalToRectangular(lo, bo, dist)
|
|
return planetGeocentricPosition{x: x, y: y, z: z, lo: lo, bo: bo}, tau, dist
|
|
}
|
|
}
|
|
ex, ey, ez := earthHeliocentricXYZN(jde, n, inst)
|
|
geoNow := planetGeocentricPositionWithEarthN(planetIndex, jde, ex, ey, ez, n, inst)
|
|
distance := math.Sqrt(geoNow.x*geoNow.x + geoNow.y*geoNow.y + geoNow.z*geoNow.z)
|
|
tau := 0.0057755183 * distance
|
|
geo := planetGeocentricPositionWithEarthN(planetIndex, jde-tau, ex, ey, ez, n, inst)
|
|
baseLo := geo.lo
|
|
baseBo := geo.bo
|
|
geo.lo = Limit360(baseLo + GXCLoWithInstance(baseLo, baseBo, jde, inst)/3600.0 + Nutation2000Bi(jde))
|
|
geo.bo = baseBo + GXCBoWithInstance(baseLo, baseBo, jde, inst)/3600.0
|
|
return geo, tau, distance
|
|
}
|
|
|
|
func planetTrueGeocentricPositionN(planetIndex int, jde float64, n int) (planetGeocentricPosition, float64) {
|
|
ex, ey, ez := earthHeliocentricXYZN(jde, n)
|
|
geoNow := planetGeocentricPositionWithEarthN(planetIndex, jde, ex, ey, ez, n)
|
|
tau := 0.0057755183 * math.Sqrt(geoNow.x*geoNow.x+geoNow.y*geoNow.y+geoNow.z*geoNow.z)
|
|
return planetGeocentricPositionWithEarthN(planetIndex, jde-tau, ex, ey, ez, n), tau
|
|
}
|
|
|
|
func planetEarthAwayExplicitN(planetIndex int, jd float64, n int) float64 {
|
|
// 新模型全精度时与视位置管线同源,掩星等组合路径取到的距离逐位一致。
|
|
if planetIndex >= 1 && planetIndex <= 7 {
|
|
if _, _, _, dist, ok := vectorApparent(planetBody[planetIndex], jd, n); ok {
|
|
return dist
|
|
}
|
|
}
|
|
geoNow := planetGeocentricPositionN(planetIndex, jd, jd, n)
|
|
return math.Sqrt(geoNow.x*geoNow.x + geoNow.y*geoNow.y + geoNow.z*geoNow.z)
|
|
}
|