// Package ltp 长期岁差的黄极与赤道极向量(J2000 平赤道坐标,±20 万年有效)。 package ltp import "math" const ( as2r = 4.848136811095359935899141e-6 d2pi = 6.283185307179586476925287 eps0 = 84381.406 * as2r ) // Vector3 三维向量 / a 3-vector. type Vector3 [3]float64 // EclipticPole 历元平黄道极 / mean ecliptic pole of epoch, epj in Julian years. func EclipticPole(epj float64) Vector3 { pqPol := [2][4]float64{ {+5851.607687, -0.1189000, -0.00028913, +0.000000101}, {-1600.886300, +1.1689818, -0.00000020, -0.000000437}, } pqPer := [8][5]float64{ {708.15, -5486.751211, -684.661560, 667.666730, -5523.863691}, {2309.00, -17.127623, 2446.283880, -2354.886252, -549.747450}, {1620.00, -617.517403, 399.671049, -428.152441, -310.998056}, {492.20, 413.442940, -356.652376, 376.202861, 421.535876}, {1183.00, 78.614193, -186.387003, 184.778874, -36.776172}, {622.00, -180.732815, -316.800070, 335.321713, -145.278396}, {882.00, -87.676083, 198.296071, -185.138669, -34.744450}, {547.00, 46.140315, 101.135679, -120.972830, 22.885731}, } t := (epj - 2000.0) / 100.0 p, q := 0.0, 0.0 for i := 0; i < 8; i++ { w := d2pi * t a := w / pqPer[i][0] s := math.Sin(a) c := math.Cos(a) p += c*pqPer[i][1] + s*pqPer[i][3] q += c*pqPer[i][2] + s*pqPer[i][4] } w := 1.0 for i := 0; i < 4; i++ { p += pqPol[0][i] * w q += pqPol[1][i] * w w *= t } p *= as2r q *= as2r z := math.Sqrt(math.Max(1.0-p*p-q*q, 0.0)) s := math.Sin(eps0) c := math.Cos(eps0) return Vector3{p, -q*c - z*s, -q*s + z*c} } // EquatorPole 历元平赤道极 / mean equator pole of epoch, epj in Julian years. func EquatorPole(epj float64) Vector3 { xyPol := [2][4]float64{ {+5453.282155, +0.4252841, -0.00037173, -0.000000152}, {-73750.930350, -0.7675452, -0.00018725, +0.000000231}, } xyPer := [14][5]float64{ {256.75, -819.940624, 75004.344875, 81491.287984, 1558.515853}, {708.15, -8444.676815, 624.033993, 787.163481, 7774.939698}, {274.20, 2600.009459, 1251.136893, 1251.296102, -2219.534038}, {241.45, 2755.175630, -1102.212834, -1257.950837, -2523.969396}, {2309.00, -167.659835, -2660.664980, -2966.799730, 247.850422}, {492.20, 871.855056, 699.291817, 639.744522, -846.485643}, {396.10, 44.769698, 153.167220, 131.600209, -1393.124055}, {288.90, -512.313065, -950.865637, -445.040117, 368.526116}, {231.10, -819.415595, 499.754645, 584.522874, 749.045012}, {1610.00, -538.071099, -145.188210, -89.756563, 444.704518}, {620.00, -189.793622, 558.116553, 524.429630, 235.934465}, {157.87, -402.922932, -23.923029, -13.549067, 374.049623}, {220.30, 179.516345, -165.405086, -210.157124, -171.330180}, {1200.00, -9.814756, 9.344131, -44.919798, -22.899655}, } t := (epj - 2000.0) / 100.0 x, y := 0.0, 0.0 for i := 0; i < 14; i++ { w := d2pi * t a := w / xyPer[i][0] s := math.Sin(a) c := math.Cos(a) x += c*xyPer[i][1] + s*xyPer[i][3] y += c*xyPer[i][2] + s*xyPer[i][4] } w := 1.0 for i := 0; i < 4; i++ { x += xyPol[0][i] * w y += xyPol[1][i] * w w *= t } x *= as2r y *= as2r w = x*x + y*y z := 0.0 if w < 1.0 { z = math.Sqrt(1.0 - w) } return Vector3{x, y, z} } // Cross 叉乘 / cross product. func Cross(a, b Vector3) Vector3 { return Vector3{ a[1]*b[2] - a[2]*b[1], a[2]*b[0] - a[0]*b[2], a[0]*b[1] - a[1]*b[0], } } // Normalize 单位向量与原模长,零向量返回零 / unit vector and norm; zero stays zero. func Normalize(p Vector3) (Vector3, float64) { w := math.Sqrt(p[0]*p[0] + p[1]*p[1] + p[2]*p[2]) if w == 0.0 { return Vector3{0, 0, 0}, 0 } return Vector3{p[0] / w, p[1] / w, p[2] / w}, w }