ootk 4.0.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (536) hide show
  1. package/CHANGELOG.md +9 -2
  2. package/README.md +0 -15
  3. package/dist/body/Celestial.d.ts +96 -0
  4. package/dist/body/Celestial.js +124 -0
  5. package/dist/body/Celestial.js.map +1 -0
  6. package/dist/body/Earth.d.ts +68 -0
  7. package/dist/body/Earth.js +198 -0
  8. package/dist/body/Earth.js.map +1 -0
  9. package/dist/body/Moon.d.ts +137 -0
  10. package/dist/body/Moon.js +464 -0
  11. package/dist/body/Moon.js.map +1 -0
  12. package/dist/body/NutationAngles.d.ts +38 -0
  13. package/dist/body/NutationAngles.js +24 -0
  14. package/dist/body/NutationAngles.js.map +1 -0
  15. package/dist/body/PrecessionAngles.d.ts +29 -0
  16. package/dist/body/PrecessionAngles.js +24 -0
  17. package/dist/body/PrecessionAngles.js.map +1 -0
  18. package/dist/body/Sun.d.ts +305 -0
  19. package/dist/body/Sun.js +548 -0
  20. package/dist/body/Sun.js.map +1 -0
  21. package/dist/body/index.d.ts +26 -0
  22. package/dist/body/index.js +27 -0
  23. package/dist/body/index.js.map +1 -0
  24. package/dist/coordinate/ClassicalElements.d.ts +132 -0
  25. package/dist/coordinate/ClassicalElements.js +279 -0
  26. package/dist/coordinate/ClassicalElements.js.map +1 -0
  27. package/dist/coordinate/EquinoctialElements.d.ts +114 -0
  28. package/dist/coordinate/EquinoctialElements.js +172 -0
  29. package/dist/coordinate/EquinoctialElements.js.map +1 -0
  30. package/dist/coordinate/FormatTle.d.ts +95 -0
  31. package/dist/coordinate/FormatTle.js +184 -0
  32. package/dist/coordinate/FormatTle.js.map +1 -0
  33. package/dist/coordinate/Geodetic.d.ts +110 -0
  34. package/dist/coordinate/Geodetic.js +163 -0
  35. package/dist/coordinate/Geodetic.js.map +1 -0
  36. package/dist/coordinate/Hill.d.ts +1 -1
  37. package/dist/coordinate/Hill.js +1 -1
  38. package/dist/coordinate/Hill.js.map +1 -1
  39. package/dist/coordinate/ITRF.d.ts +75 -0
  40. package/dist/coordinate/ITRF.js +135 -0
  41. package/dist/coordinate/ITRF.js.map +1 -0
  42. package/dist/coordinate/J2000.d.ts +65 -0
  43. package/dist/coordinate/J2000.js +120 -0
  44. package/dist/coordinate/J2000.js.map +1 -0
  45. package/dist/coordinate/RIC.d.ts +64 -0
  46. package/dist/coordinate/RIC.js +79 -0
  47. package/dist/coordinate/RIC.js.map +1 -0
  48. package/dist/coordinate/RelativeState.d.ts +70 -0
  49. package/dist/coordinate/RelativeState.js +79 -0
  50. package/dist/coordinate/RelativeState.js.map +1 -0
  51. package/dist/coordinate/StateVector.d.ts +76 -0
  52. package/dist/coordinate/StateVector.js +97 -0
  53. package/dist/coordinate/StateVector.js.map +1 -0
  54. package/dist/coordinate/TEME.d.ts +57 -0
  55. package/dist/coordinate/TEME.js +89 -0
  56. package/dist/coordinate/TEME.js.map +1 -0
  57. package/dist/coordinate/Tle.d.ts +430 -0
  58. package/dist/coordinate/Tle.js +865 -0
  59. package/dist/coordinate/Tle.js.map +1 -0
  60. package/dist/coordinate/index.d.ts +11 -0
  61. package/dist/coordinate/index.js +12 -0
  62. package/dist/coordinate/index.js.map +1 -1
  63. package/dist/coordinate/tle-format-data.d.ts +41 -0
  64. package/dist/coordinate/tle-format-data.js +46 -0
  65. package/dist/coordinate/tle-format-data.js.map +1 -0
  66. package/dist/covariance/CovarianceSample.d.ts +1 -1
  67. package/dist/covariance/CovarianceSample.js +1 -1
  68. package/dist/covariance/CovarianceSample.js.map +1 -1
  69. package/dist/covariance/StateCovariance.d.ts +1 -1
  70. package/dist/covariance/StateCovariance.js +1 -1
  71. package/dist/covariance/StateCovariance.js.map +1 -1
  72. package/dist/data/DataHandler.d.ts +66 -0
  73. package/dist/data/DataHandler.js +80 -0
  74. package/dist/data/DataHandler.js.map +1 -0
  75. package/dist/data/values/Egm96Data.d.ts +37 -0
  76. package/dist/data/values/Egm96Data.js +63 -0
  77. package/dist/data/values/Egm96Data.js.map +1 -0
  78. package/dist/data/values/HpAtmosphereData.d.ts +33 -0
  79. package/dist/data/values/HpAtmosphereData.js +58 -0
  80. package/dist/data/values/HpAtmosphereData.js.map +1 -0
  81. package/dist/data/values/HpAtmosphereResult.d.ts +29 -0
  82. package/dist/data/values/HpAtmosphereResult.js +38 -0
  83. package/dist/data/values/HpAtmosphereResult.js.map +1 -0
  84. package/dist/data/values/Iau1980Data.d.ts +36 -0
  85. package/dist/data/values/Iau1980Data.js +52 -0
  86. package/dist/data/values/Iau1980Data.js.map +1 -0
  87. package/dist/data/values/LeapSecond.d.ts +27 -0
  88. package/dist/data/values/LeapSecond.js +35 -0
  89. package/dist/data/values/LeapSecond.js.map +1 -0
  90. package/dist/data/values/LeapSecondData.d.ts +41 -0
  91. package/dist/data/values/LeapSecondData.js +103 -0
  92. package/dist/data/values/LeapSecondData.js.map +1 -0
  93. package/dist/data/values/egm96.d.ts +24 -0
  94. package/dist/data/values/egm96.js +726 -0
  95. package/dist/data/values/egm96.js.map +1 -0
  96. package/dist/data/values/hpAtmosphere.d.ts +24 -0
  97. package/dist/data/values/hpAtmosphere.js +76 -0
  98. package/dist/data/values/hpAtmosphere.js.map +1 -0
  99. package/dist/data/values/iau1980.d.ts +24 -0
  100. package/dist/data/values/iau1980.js +30 -0
  101. package/dist/data/values/iau1980.js.map +1 -0
  102. package/dist/enums/AngularDiameterMethod.d.ts +27 -0
  103. package/dist/enums/AngularDiameterMethod.js +29 -0
  104. package/dist/enums/AngularDiameterMethod.js.map +1 -0
  105. package/dist/enums/AngularDistanceMethod.d.ts +27 -0
  106. package/dist/enums/AngularDistanceMethod.js +29 -0
  107. package/dist/enums/AngularDistanceMethod.js.map +1 -0
  108. package/dist/enums/OrbitRegime.d.ts +30 -0
  109. package/dist/enums/OrbitRegime.js +32 -0
  110. package/dist/enums/OrbitRegime.js.map +1 -0
  111. package/dist/enums/PassType.d.ts +28 -0
  112. package/dist/enums/PassType.js +30 -0
  113. package/dist/enums/PassType.js.map +1 -0
  114. package/dist/enums/Sgp4OpsMode.d.ts +26 -0
  115. package/dist/enums/Sgp4OpsMode.js +28 -0
  116. package/dist/enums/Sgp4OpsMode.js.map +1 -0
  117. package/dist/enums/index.d.ts +5 -0
  118. package/dist/enums/index.js +5 -0
  119. package/dist/enums/index.js.map +1 -1
  120. package/dist/force/AtmosphericDrag.d.ts +1 -1
  121. package/dist/force/AtmosphericDrag.js +1 -1
  122. package/dist/force/AtmosphericDrag.js.map +1 -1
  123. package/dist/force/EarthGravity.d.ts +1 -1
  124. package/dist/force/EarthGravity.js +1 -1
  125. package/dist/force/EarthGravity.js.map +1 -1
  126. package/dist/force/Force.d.ts +1 -1
  127. package/dist/force/ForceModel.d.ts +1 -1
  128. package/dist/force/ForceModel.js +1 -1
  129. package/dist/force/ForceModel.js.map +1 -1
  130. package/dist/force/Gravity.d.ts +1 -1
  131. package/dist/force/Gravity.js +1 -1
  132. package/dist/force/Gravity.js.map +1 -1
  133. package/dist/force/SolarRadiationPressure.d.ts +1 -1
  134. package/dist/force/SolarRadiationPressure.js +1 -1
  135. package/dist/force/SolarRadiationPressure.js.map +1 -1
  136. package/dist/force/ThirdBodyGravity.d.ts +1 -1
  137. package/dist/force/ThirdBodyGravity.js +1 -1
  138. package/dist/force/ThirdBodyGravity.js.map +1 -1
  139. package/dist/force/Thrust.d.ts +1 -1
  140. package/dist/force/Thrust.js +1 -1
  141. package/dist/force/Thrust.js.map +1 -1
  142. package/dist/interfaces/BaseObjectParams.d.ts +31 -0
  143. package/dist/interfaces/BaseObjectParams.js +24 -0
  144. package/dist/interfaces/BaseObjectParams.js.map +1 -0
  145. package/dist/interfaces/ClassicalElementsParams.d.ts +33 -0
  146. package/dist/interfaces/ClassicalElementsParams.js +24 -0
  147. package/dist/interfaces/ClassicalElementsParams.js.map +1 -0
  148. package/dist/interfaces/EquinoctialElementsParams.d.ts +35 -0
  149. package/dist/interfaces/EquinoctialElementsParams.js +24 -0
  150. package/dist/interfaces/EquinoctialElementsParams.js.map +1 -0
  151. package/dist/interfaces/GroundPositionParams.d.ts +28 -0
  152. package/dist/interfaces/GroundPositionParams.js +24 -0
  153. package/dist/interfaces/GroundPositionParams.js.map +1 -0
  154. package/dist/interfaces/OmmFormat.d.ts +62 -0
  155. package/dist/interfaces/OmmFormat.js +2 -0
  156. package/dist/interfaces/OmmFormat.js.map +1 -0
  157. package/dist/interfaces/OptionsParams.d.ts +3 -0
  158. package/dist/interfaces/OptionsParams.js +2 -0
  159. package/dist/interfaces/OptionsParams.js.map +1 -0
  160. package/dist/interfaces/RfSensorParams.d.ts +1 -1
  161. package/dist/interfaces/SatelliteParams.d.ts +18 -0
  162. package/dist/interfaces/SatelliteParams.js +2 -0
  163. package/dist/interfaces/SatelliteParams.js.map +1 -0
  164. package/dist/interfaces/SensorParams.d.ts +38 -0
  165. package/dist/interfaces/SensorParams.js +2 -0
  166. package/dist/interfaces/SensorParams.js.map +1 -0
  167. package/dist/interfaces/StarObjectParams.d.ts +10 -0
  168. package/dist/interfaces/StarObjectParams.js +2 -0
  169. package/dist/interfaces/StarObjectParams.js.map +1 -0
  170. package/dist/interfaces/TimeVariables.d.ts +6 -0
  171. package/dist/interfaces/TimeVariables.js +2 -0
  172. package/dist/interfaces/TimeVariables.js.map +1 -0
  173. package/dist/interfaces/index.d.ts +8 -0
  174. package/dist/interpolator/ChebyshevCoefficients.d.ts +1 -1
  175. package/dist/interpolator/ChebyshevCoefficients.js +1 -1
  176. package/dist/interpolator/ChebyshevCoefficients.js.map +1 -1
  177. package/dist/interpolator/ChebyshevInterpolator.d.ts +1 -1
  178. package/dist/interpolator/ChebyshevInterpolator.js +1 -1
  179. package/dist/interpolator/ChebyshevInterpolator.js.map +1 -1
  180. package/dist/interpolator/CubicSpline.d.ts +1 -1
  181. package/dist/interpolator/CubicSplineInterpolator.d.ts +1 -1
  182. package/dist/interpolator/CubicSplineInterpolator.js +1 -1
  183. package/dist/interpolator/CubicSplineInterpolator.js.map +1 -1
  184. package/dist/interpolator/Interpolator.d.ts +1 -1
  185. package/dist/interpolator/Interpolator.js +1 -1
  186. package/dist/interpolator/Interpolator.js.map +1 -1
  187. package/dist/interpolator/LagrangeInterpolator.d.ts +1 -1
  188. package/dist/interpolator/LagrangeInterpolator.js +1 -1
  189. package/dist/interpolator/LagrangeInterpolator.js.map +1 -1
  190. package/dist/interpolator/StateInterpolator.d.ts +1 -1
  191. package/dist/interpolator/VerletBlendInterpolator.d.ts +1 -1
  192. package/dist/interpolator/VerletBlendInterpolator.js +1 -1
  193. package/dist/interpolator/VerletBlendInterpolator.js.map +1 -1
  194. package/dist/main.d.ts +11 -3
  195. package/dist/main.js +11 -3
  196. package/dist/main.js.map +1 -1
  197. package/dist/maneuver/TwoBurnOrbitTransfer.d.ts +1 -1
  198. package/dist/maneuver/TwoBurnOrbitTransfer.js +1 -1
  199. package/dist/maneuver/TwoBurnOrbitTransfer.js.map +1 -1
  200. package/dist/maneuver/Waypoint.d.ts +1 -1
  201. package/dist/maneuver/Waypoint.js +1 -1
  202. package/dist/maneuver/Waypoint.js.map +1 -1
  203. package/dist/objects/BaseObject.d.ts +74 -0
  204. package/dist/objects/BaseObject.js +151 -0
  205. package/dist/objects/BaseObject.js.map +1 -0
  206. package/dist/objects/DetailedSatellite.d.ts +3 -1
  207. package/dist/objects/DetailedSatellite.js +4 -2
  208. package/dist/objects/DetailedSatellite.js.map +1 -1
  209. package/dist/objects/DetailedSensor.d.ts +2 -1
  210. package/dist/objects/DetailedSensor.js +1 -1
  211. package/dist/objects/DetailedSensor.js.map +1 -1
  212. package/dist/objects/GroundObject.d.ts +85 -0
  213. package/dist/objects/GroundObject.js +143 -0
  214. package/dist/objects/GroundObject.js.map +1 -0
  215. package/dist/objects/LandObject.d.ts +2 -1
  216. package/dist/objects/LandObject.js +1 -1
  217. package/dist/objects/LandObject.js.map +1 -1
  218. package/dist/objects/Marker.d.ts +1 -1
  219. package/dist/objects/Marker.js +1 -1
  220. package/dist/objects/Marker.js.map +1 -1
  221. package/dist/objects/RfSensor.d.ts +1 -2
  222. package/dist/objects/RfSensor.js +1 -2
  223. package/dist/objects/RfSensor.js.map +1 -1
  224. package/dist/objects/Satellite.d.ts +226 -0
  225. package/dist/objects/Satellite.js +443 -0
  226. package/dist/objects/Satellite.js.map +1 -0
  227. package/dist/objects/Sensor.d.ts +100 -0
  228. package/dist/objects/Sensor.js +239 -0
  229. package/dist/objects/Sensor.js.map +1 -0
  230. package/dist/objects/Star.d.ts +36 -0
  231. package/dist/objects/Star.js +59 -0
  232. package/dist/objects/Star.js.map +1 -0
  233. package/dist/objects/index.d.ts +5 -0
  234. package/dist/objects/index.js +5 -0
  235. package/dist/objects/index.js.map +1 -1
  236. package/dist/observation/Observation.d.ts +1 -1
  237. package/dist/observation/ObservationOptical.d.ts +1 -1
  238. package/dist/observation/ObservationOptical.js +1 -1
  239. package/dist/observation/ObservationOptical.js.map +1 -1
  240. package/dist/observation/ObservationRadar.d.ts +1 -1
  241. package/dist/observation/ObservationRadar.js +1 -1
  242. package/dist/observation/ObservationRadar.js.map +1 -1
  243. package/dist/observation/ObservationUtils.d.ts +3 -1
  244. package/dist/observation/ObservationUtils.js +15 -1
  245. package/dist/observation/ObservationUtils.js.map +1 -1
  246. package/dist/observation/RAE.d.ts +111 -0
  247. package/dist/observation/RAE.js +215 -0
  248. package/dist/observation/RAE.js.map +1 -0
  249. package/dist/observation/RadecGeocentric.d.ts +111 -0
  250. package/dist/observation/RadecGeocentric.js +169 -0
  251. package/dist/observation/RadecGeocentric.js.map +1 -0
  252. package/dist/observation/RadecTopocentric.d.ts +123 -0
  253. package/dist/observation/RadecTopocentric.js +196 -0
  254. package/dist/observation/RadecTopocentric.js.map +1 -0
  255. package/dist/observation/index.d.ts +26 -0
  256. package/dist/observation/index.js +27 -0
  257. package/dist/observation/index.js.map +1 -0
  258. package/dist/operations/BoxMuller.d.ts +1 -1
  259. package/dist/operations/BoxMuller.js +1 -1
  260. package/dist/operations/BoxMuller.js.map +1 -1
  261. package/dist/operations/EulerAngles.d.ts +1 -1
  262. package/dist/operations/EulerAngles.js +1 -1
  263. package/dist/operations/EulerAngles.js.map +1 -1
  264. package/dist/operations/Matrix.d.ts +170 -0
  265. package/dist/operations/Matrix.js +405 -0
  266. package/dist/operations/Matrix.js.map +1 -0
  267. package/dist/operations/Quaternion.d.ts +1 -1
  268. package/dist/operations/Quaternion.js +1 -1
  269. package/dist/operations/Quaternion.js.map +1 -1
  270. package/dist/operations/Random.d.ts +40 -0
  271. package/dist/operations/Random.js +50 -0
  272. package/dist/operations/Random.js.map +1 -0
  273. package/dist/operations/RandomGaussianSource.d.ts +1 -1
  274. package/dist/operations/RandomGaussianSource.js +1 -1
  275. package/dist/operations/RandomGaussianSource.js.map +1 -1
  276. package/dist/operations/Vector.d.ts +262 -0
  277. package/dist/operations/Vector.js +415 -0
  278. package/dist/operations/Vector.js.map +1 -0
  279. package/dist/operations/Vector3D.d.ts +86 -0
  280. package/dist/operations/Vector3D.js +241 -0
  281. package/dist/operations/Vector3D.js.map +1 -0
  282. package/dist/operations/operations.d.ts +26 -0
  283. package/dist/operations/operations.js +27 -0
  284. package/dist/operations/operations.js.map +1 -0
  285. package/dist/optimize/ChebyshevCompressor.js +1 -1
  286. package/dist/optimize/ChebyshevCompressor.js.map +1 -1
  287. package/dist/optimize/PolynomialRegression.js +1 -1
  288. package/dist/optimize/PolynomialRegression.js.map +1 -1
  289. package/dist/optimize/SimplexEntry.js +1 -1
  290. package/dist/optimize/SimplexEntry.js.map +1 -1
  291. package/dist/orbit_determination/BatchLeastSquaresOD.d.ts +1 -1
  292. package/dist/orbit_determination/BatchLeastSquaresOD.js +1 -1
  293. package/dist/orbit_determination/BatchLeastSquaresOD.js.map +1 -1
  294. package/dist/orbit_determination/BatchLeastSquaresResult.d.ts +1 -1
  295. package/dist/orbit_determination/GibbsIOD.d.ts +1 -1
  296. package/dist/orbit_determination/GibbsIOD.js +1 -1
  297. package/dist/orbit_determination/GibbsIOD.js.map +1 -1
  298. package/dist/orbit_determination/GoodingIOD.d.ts +1 -1
  299. package/dist/orbit_determination/GoodingIOD.js +1 -1
  300. package/dist/orbit_determination/GoodingIOD.js.map +1 -1
  301. package/dist/orbit_determination/HerrickGibbsIOD.d.ts +1 -1
  302. package/dist/orbit_determination/HerrickGibbsIOD.js +1 -1
  303. package/dist/orbit_determination/HerrickGibbsIOD.js.map +1 -1
  304. package/dist/orbit_determination/LambertIOD.d.ts +1 -1
  305. package/dist/orbit_determination/LambertIOD.js +1 -1
  306. package/dist/orbit_determination/LambertIOD.js.map +1 -1
  307. package/dist/orbit_determination/ModifiedGoodingIOD.d.ts +1 -1
  308. package/dist/orbit_determination/ModifiedGoodingIOD.js +1 -1
  309. package/dist/orbit_determination/ModifiedGoodingIOD.js.map +1 -1
  310. package/dist/orbit_determination/index.d.ts +7 -0
  311. package/dist/orbit_determination/index.js +8 -0
  312. package/dist/orbit_determination/index.js.map +1 -0
  313. package/dist/propagator/KeplerPropagator.d.ts +1 -1
  314. package/dist/propagator/KeplerPropagator.js +1 -1
  315. package/dist/propagator/KeplerPropagator.js.map +1 -1
  316. package/dist/propagator/Propagator.d.ts +1 -1
  317. package/dist/propagator/Propagator.js +1 -1
  318. package/dist/propagator/Propagator.js.map +1 -1
  319. package/dist/propagator/RkCheckpoint.d.ts +1 -1
  320. package/dist/propagator/RkResult.d.ts +1 -1
  321. package/dist/propagator/RungeKutta4Propagator.d.ts +1 -1
  322. package/dist/propagator/RungeKutta4Propagator.js +1 -1
  323. package/dist/propagator/RungeKutta4Propagator.js.map +1 -1
  324. package/dist/propagator/RungeKuttaAdaptive.d.ts +1 -1
  325. package/dist/propagator/RungeKuttaAdaptive.js +1 -1
  326. package/dist/propagator/RungeKuttaAdaptive.js.map +1 -1
  327. package/dist/propagator/Sgp4Propagator.d.ts +1 -1
  328. package/dist/sgp4/index.d.ts +23 -0
  329. package/dist/sgp4/index.js +24 -0
  330. package/dist/sgp4/index.js.map +1 -0
  331. package/dist/sgp4/sgp4-error.d.ts +22 -0
  332. package/dist/sgp4/sgp4-error.js +44 -0
  333. package/dist/sgp4/sgp4-error.js.map +1 -0
  334. package/dist/sgp4/sgp4.d.ts +102 -0
  335. package/dist/sgp4/sgp4.js +3167 -0
  336. package/dist/sgp4/sgp4.js.map +1 -0
  337. package/dist/smoothing/ExponentialSmoothing.d.ts +1 -1
  338. package/dist/time/Epoch.d.ts +44 -0
  339. package/dist/time/Epoch.js +109 -0
  340. package/dist/time/Epoch.js.map +1 -0
  341. package/dist/time/EpochGPS.d.ts +42 -0
  342. package/dist/time/EpochGPS.js +70 -0
  343. package/dist/time/EpochGPS.js.map +1 -0
  344. package/dist/time/EpochTAI.d.ts +26 -0
  345. package/dist/time/EpochTAI.js +27 -0
  346. package/dist/time/EpochTAI.js.map +1 -0
  347. package/dist/time/EpochTDB.d.ts +26 -0
  348. package/dist/time/EpochTDB.js +27 -0
  349. package/dist/time/EpochTDB.js.map +1 -0
  350. package/dist/time/EpochTT.d.ts +26 -0
  351. package/dist/time/EpochTT.js +27 -0
  352. package/dist/time/EpochTT.js.map +1 -0
  353. package/dist/time/EpochUTC.d.ts +59 -0
  354. package/dist/time/EpochUTC.js +137 -0
  355. package/dist/time/EpochUTC.js.map +1 -0
  356. package/dist/time/EpochWindow.d.ts +28 -0
  357. package/dist/time/EpochWindow.js +31 -0
  358. package/dist/time/EpochWindow.js.map +1 -0
  359. package/dist/time/TimeStamped.d.ts +43 -0
  360. package/dist/time/TimeStamped.js +46 -0
  361. package/dist/time/TimeStamped.js.map +1 -0
  362. package/dist/time/index.d.ts +30 -0
  363. package/dist/time/index.js +31 -0
  364. package/dist/time/index.js.map +1 -0
  365. package/dist/transforms/TransformCache.d.ts +27 -0
  366. package/dist/transforms/TransformCache.js +41 -0
  367. package/dist/transforms/TransformCache.js.map +1 -0
  368. package/dist/transforms/conversions.d.ts +63 -0
  369. package/dist/transforms/conversions.js +88 -0
  370. package/dist/transforms/conversions.js.map +1 -0
  371. package/dist/transforms/index.d.ts +1 -0
  372. package/dist/transforms/index.js +1 -0
  373. package/dist/transforms/index.js.map +1 -1
  374. package/dist/transforms/transforms.d.ts +166 -2
  375. package/dist/transforms/transforms.js +372 -1
  376. package/dist/transforms/transforms.js.map +1 -1
  377. package/dist/types/types.d.ts +674 -2
  378. package/dist/types/types.js +36 -0
  379. package/dist/types/types.js.map +1 -1
  380. package/dist/utils/constants.d.ts +80 -0
  381. package/dist/utils/constants.js +87 -0
  382. package/dist/utils/constants.js.map +1 -0
  383. package/dist/utils/functions.d.ts +228 -0
  384. package/dist/utils/functions.js +476 -0
  385. package/dist/utils/functions.js.map +1 -1
  386. package/dist/utils/index.d.ts +3 -1
  387. package/dist/utils/index.js +3 -1
  388. package/dist/utils/index.js.map +1 -1
  389. package/dist/utils/jacobian.d.ts +1 -1
  390. package/dist/utils/jacobian.js +1 -1
  391. package/dist/utils/jacobian.js.map +1 -1
  392. package/dist/utils/linearDistance.d.ts +8 -0
  393. package/dist/utils/linearDistance.js +10 -0
  394. package/dist/utils/linearDistance.js.map +1 -0
  395. package/package.json +4 -7
  396. package/src/body/Celestial.ts +134 -0
  397. package/src/body/Earth.ts +260 -0
  398. package/src/body/Moon.ts +556 -0
  399. package/src/body/NutationAngles.ts +40 -0
  400. package/src/body/PrecessionAngles.ts +31 -0
  401. package/src/body/Sun.ts +669 -0
  402. package/src/body/index.ts +27 -0
  403. package/src/body/suncalc.LICENSE.md +18 -0
  404. package/src/coordinate/ClassicalElements.ts +326 -0
  405. package/src/coordinate/EquinoctialElements.ts +189 -0
  406. package/src/coordinate/FormatTle.ts +214 -0
  407. package/src/coordinate/Geodetic.ts +186 -0
  408. package/src/coordinate/Hill.ts +1 -1
  409. package/src/coordinate/ITRF.ts +146 -0
  410. package/src/coordinate/J2000.ts +130 -0
  411. package/src/coordinate/RIC.ts +87 -0
  412. package/src/coordinate/RelativeState.ts +101 -0
  413. package/src/coordinate/StateVector.ts +122 -0
  414. package/src/coordinate/TEME.ts +97 -0
  415. package/src/coordinate/Tle.ts +1024 -0
  416. package/src/coordinate/index.ts +12 -0
  417. package/src/coordinate/tle-format-data.ts +47 -0
  418. package/src/covariance/CovarianceSample.ts +1 -1
  419. package/src/covariance/StateCovariance.ts +1 -1
  420. package/src/data/DataHandler.ts +88 -0
  421. package/src/data/values/Egm96Data.ts +75 -0
  422. package/src/data/values/HpAtmosphereData.ts +76 -0
  423. package/src/data/values/HpAtmosphereResult.ts +41 -0
  424. package/src/data/values/Iau1980Data.ts +63 -0
  425. package/src/data/values/LeapSecond.ts +37 -0
  426. package/src/data/values/LeapSecondData.ts +113 -0
  427. package/src/data/values/egm96.ts +728 -0
  428. package/src/data/values/hpAtmosphere.ts +79 -0
  429. package/src/data/values/iau1980.ts +32 -0
  430. package/src/enums/AngularDiameterMethod.ts +28 -0
  431. package/src/enums/AngularDistanceMethod.ts +28 -0
  432. package/src/enums/OrbitRegime.ts +31 -0
  433. package/src/enums/PassType.ts +29 -0
  434. package/src/enums/Sgp4OpsMode.ts +27 -0
  435. package/src/enums/index.ts +5 -0
  436. package/src/force/AtmosphericDrag.ts +1 -1
  437. package/src/force/EarthGravity.ts +1 -1
  438. package/src/force/Force.ts +1 -1
  439. package/src/force/ForceModel.ts +1 -1
  440. package/src/force/Gravity.ts +1 -1
  441. package/src/force/SolarRadiationPressure.ts +1 -1
  442. package/src/force/ThirdBodyGravity.ts +1 -1
  443. package/src/force/Thrust.ts +1 -1
  444. package/src/interfaces/BaseObjectParams.ts +33 -0
  445. package/src/interfaces/ClassicalElementsParams.ts +35 -0
  446. package/src/interfaces/EquinoctialElementsParams.ts +37 -0
  447. package/src/interfaces/GroundPositionParams.ts +30 -0
  448. package/src/interfaces/OmmFormat.ts +63 -0
  449. package/src/interfaces/OptionsParams.ts +3 -0
  450. package/src/interfaces/RfSensorParams.ts +1 -1
  451. package/src/interfaces/SatelliteParams.ts +20 -0
  452. package/src/interfaces/SensorParams.ts +39 -0
  453. package/src/interfaces/StarObjectParams.ts +11 -0
  454. package/src/interfaces/TimeVariables.ts +7 -0
  455. package/src/interfaces/index.ts +8 -0
  456. package/src/interpolator/ChebyshevCoefficients.ts +1 -1
  457. package/src/interpolator/ChebyshevInterpolator.ts +1 -1
  458. package/src/interpolator/CubicSpline.ts +1 -1
  459. package/src/interpolator/CubicSplineInterpolator.ts +1 -1
  460. package/src/interpolator/Interpolator.ts +1 -1
  461. package/src/interpolator/LagrangeInterpolator.ts +1 -1
  462. package/src/interpolator/StateInterpolator.ts +1 -1
  463. package/src/interpolator/VerletBlendInterpolator.ts +1 -1
  464. package/src/main.ts +11 -3
  465. package/src/maneuver/TwoBurnOrbitTransfer.ts +1 -1
  466. package/src/maneuver/Waypoint.ts +1 -1
  467. package/src/objects/BaseObject.ts +171 -0
  468. package/src/objects/DetailedSatellite.ts +5 -3
  469. package/src/objects/DetailedSensor.ts +2 -1
  470. package/src/objects/GroundObject.ts +176 -0
  471. package/src/objects/LandObject.ts +2 -1
  472. package/src/objects/Marker.ts +1 -1
  473. package/src/objects/RfSensor.ts +1 -2
  474. package/src/objects/Satellite.ts +552 -0
  475. package/src/objects/Sensor.ts +280 -0
  476. package/src/objects/Star.ts +96 -0
  477. package/src/objects/index.ts +5 -0
  478. package/src/observation/Observation.ts +1 -1
  479. package/src/observation/ObservationOptical.ts +1 -1
  480. package/src/observation/ObservationRadar.ts +1 -1
  481. package/src/observation/ObservationUtils.ts +30 -1
  482. package/src/observation/RAE.ts +262 -0
  483. package/src/observation/RadecGeocentric.ts +206 -0
  484. package/src/observation/RadecTopocentric.ts +241 -0
  485. package/src/observation/index.ts +27 -0
  486. package/src/operations/BoxMuller.ts +1 -1
  487. package/src/operations/EulerAngles.ts +1 -1
  488. package/src/operations/Matrix.ts +473 -0
  489. package/src/operations/Quaternion.ts +1 -1
  490. package/src/operations/Random.ts +54 -0
  491. package/src/operations/RandomGaussianSource.ts +1 -1
  492. package/src/operations/Vector.ts +484 -0
  493. package/src/operations/Vector3D.ts +289 -0
  494. package/src/operations/operations.ts +27 -0
  495. package/src/optimize/ChebyshevCompressor.ts +1 -1
  496. package/src/optimize/PolynomialRegression.ts +1 -1
  497. package/src/optimize/SimplexEntry.ts +1 -1
  498. package/src/orbit_determination/BatchLeastSquaresOD.ts +1 -1
  499. package/src/orbit_determination/BatchLeastSquaresResult.ts +1 -1
  500. package/src/orbit_determination/GibbsIOD.ts +3 -1
  501. package/src/orbit_determination/GoodingIOD.ts +1 -1
  502. package/src/orbit_determination/HerrickGibbsIOD.ts +1 -1
  503. package/src/orbit_determination/LambertIOD.ts +1 -1
  504. package/src/orbit_determination/ModifiedGoodingIOD.ts +1 -1
  505. package/src/orbit_determination/index.ts +7 -0
  506. package/src/propagator/KeplerPropagator.ts +1 -1
  507. package/src/propagator/Propagator.ts +1 -1
  508. package/src/propagator/RkCheckpoint.ts +1 -1
  509. package/src/propagator/RkResult.ts +1 -1
  510. package/src/propagator/RungeKutta4Propagator.ts +1 -1
  511. package/src/propagator/RungeKuttaAdaptive.ts +1 -1
  512. package/src/propagator/Sgp4Propagator.ts +1 -1
  513. package/src/sgp4/index.ts +24 -0
  514. package/src/sgp4/sgp4-error.ts +53 -0
  515. package/src/sgp4/sgp4.LICENSE.md +28 -0
  516. package/src/sgp4/sgp4.ts +3986 -0
  517. package/src/smoothing/ExponentialSmoothing.ts +1 -1
  518. package/src/time/Epoch.ts +128 -0
  519. package/src/time/EpochGPS.ts +76 -0
  520. package/src/time/EpochTAI.ts +27 -0
  521. package/src/time/EpochTDB.ts +27 -0
  522. package/src/time/EpochTT.ts +27 -0
  523. package/src/time/EpochUTC.ts +188 -0
  524. package/src/time/EpochWindow.ts +33 -0
  525. package/src/time/TimeStamped.ts +50 -0
  526. package/src/time/index.ts +31 -0
  527. package/src/transforms/TransformCache.ts +46 -0
  528. package/src/transforms/conversions.ts +98 -0
  529. package/src/transforms/index.ts +1 -0
  530. package/src/transforms/transforms.ts +478 -2
  531. package/src/types/types.ts +721 -2
  532. package/src/utils/constants.ts +113 -0
  533. package/src/utils/functions.ts +562 -0
  534. package/src/utils/index.ts +3 -1
  535. package/src/utils/jacobian.ts +1 -1
  536. package/src/utils/linearDistance.ts +11 -0
@@ -0,0 +1,3986 @@
1
+ /**
2
+ * @author Theodore Kruczek.
3
+ * @license MIT
4
+ * @copyright (c) 2022-2025 Theodore Kruczek Permission is
5
+ * hereby granted, free of charge, to any person obtaining a copy of this
6
+ * software and associated documentation files (the "Software"), to deal in the
7
+ * Software without restriction, including without limitation the rights to use,
8
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ * the Software, and to permit persons to whom the Software is furnished to do
10
+ * so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ * @copyright (c) 2012–2016 Brandon Rhodes
23
+ * This was ported from the python-sgp4 library by Brandon Rhodes.
24
+ */
25
+
26
+ // NOTE: This file is meant to maintain as much of the original format as possible.
27
+ /* eslint-disable complexity */
28
+ /* eslint-disable max-statements */
29
+ /* eslint-disable max-lines-per-function */
30
+ /* eslint-disable max-lines */
31
+ /* eslint-disable @typescript-eslint/no-loss-of-precision */
32
+
33
+ import { OmmParsedDataFormat } from '../interfaces/OmmFormat.js';
34
+ import { Sgp4OpsMode } from '../enums/Sgp4OpsMode.js';
35
+ import {
36
+ GreenwichMeanSiderealTime, Kilometers, KilometersPerSecond, SatelliteRecord, StateVectorSgp4, Vec3Flat,
37
+ } from '../types/types.js';
38
+ import { DEG2RAD, PI, TAU, temp4, x2o3 } from '../utils/constants.js';
39
+ import { Sgp4ErrorCode } from './sgp4-error.js';
40
+ import { Tle } from '../main.js';
41
+
42
+ export enum Sgp4GravConstants {
43
+ wgs72old = 'wgs72old',
44
+ wgs72 = 'wgs72',
45
+ wgs84 = 'wgs84',
46
+ }
47
+
48
+ export enum Sgp4Methods {
49
+ NEAR_EARTH = 'n',
50
+ DEEP_SPACE = 'd',
51
+ }
52
+
53
+ interface DsInitParams {
54
+ xke: number;
55
+ cosim: number;
56
+ argpo: number;
57
+ s1: number;
58
+ s2: number;
59
+ s3: number;
60
+ s4: number;
61
+ s5: number;
62
+ sinim: number;
63
+ ss1: number;
64
+ ss2: number;
65
+ ss3: number;
66
+ ss4: number;
67
+ ss5: number;
68
+ sz1: number;
69
+ sz3: number;
70
+ sz11: number;
71
+ sz13: number;
72
+ sz21: number;
73
+ sz23: number;
74
+ sz31: number;
75
+ sz33: number;
76
+ t: number;
77
+ tc: number;
78
+ gsto: number;
79
+ mo: number;
80
+ mdot: number;
81
+ no: number;
82
+ nodeo: number;
83
+ nodedot: number;
84
+ xPIdot: number;
85
+ z1: number;
86
+ z3: number;
87
+ z11: number;
88
+ z13: number;
89
+ z21: number;
90
+ z23: number;
91
+ z31: number;
92
+ z33: number;
93
+ ecco: number;
94
+ eccsq: number;
95
+ emsq: number;
96
+ em: number;
97
+ argpm: number;
98
+ inclm: number;
99
+ mm: number;
100
+ nm: number;
101
+ nodem: number;
102
+ irez: number;
103
+ atime: number;
104
+ d2201: number;
105
+ d2211: number;
106
+ d3210: number;
107
+ d3222: number;
108
+ d4410: number;
109
+ d4422: number;
110
+ d5220: number;
111
+ d5232: number;
112
+ d5421: number;
113
+ d5433: number;
114
+ dedt: number;
115
+ didt: number;
116
+ dmdt: number;
117
+ dnodt: number;
118
+ domdt: number;
119
+ del1: number;
120
+ del2: number;
121
+ del3: number;
122
+ xfact: number;
123
+ xlamo: number;
124
+ xli: number;
125
+ xni: number;
126
+ }
127
+
128
+ /** Ootk -- Some variables imported from outside the class at the top */
129
+ const fasx2 = 0.13130908;
130
+ const fasx4 = 2.8843198;
131
+ const fasx6 = 0.37448087;
132
+ const g22 = 5.7686396;
133
+ const g32 = 0.95240898;
134
+ const g44 = 1.8014998;
135
+ const g52 = 1.050833;
136
+ const g54 = 4.4108898;
137
+ const rptim = 4.37526908801129966e-3; // Equates to 7.29211514668855e-5 rad/sec
138
+ const stepp = 720.0;
139
+ const stepn = -720.0;
140
+ const step2 = 259200.0;
141
+
142
+ /*
143
+ * ----------------------------------------------------------------
144
+ *
145
+ * sgp4unit.cpp
146
+ *
147
+ * this file contains the sgp4 procedures for analytical propagation
148
+ * of a satellite. the code was originally released in the 1980 and 1986
149
+ * spacetrack papers. a detailed discussion of the theory and history
150
+ * may be found in the 2006 aiaa paper by vallado, crawford, hujsak,
151
+ * and kelso.
152
+ *
153
+ * companion code for
154
+ * fundamentals of astrodynamics and applications
155
+ * 2013
156
+ * by david vallado
157
+ *
158
+ * (w) 719-573-2600, email dvallado@agi.com, davallado@gmail.com
159
+ *
160
+ * current :
161
+ * 12 mar 20 david vallado
162
+ * chg satnum to string for alpha 5 or 9-digit
163
+ * changes :
164
+ * 7 dec 15 david vallado
165
+ * fix jd, jdfrac
166
+ * 3 nov 14 david vallado
167
+ * update to msvs2013 c++
168
+ * 30 aug 10 david vallado
169
+ * delete unused variables in initl
170
+ * replace pow integer 2, 3 with multiplies for speed
171
+ * 3 nov 08 david vallado
172
+ * put returns in for error codes
173
+ * 29 sep 08 david vallado
174
+ * fix atime for faster operation in dspace
175
+ * add operationmode for afspc (a) or improved (i)
176
+ * performance mode
177
+ * 16 jun 08 david vallado
178
+ * update small eccentricity check
179
+ * 16 nov 07 david vallado
180
+ * misc fixes for better compliance
181
+ * 20 apr 07 david vallado
182
+ * misc fixes for constants
183
+ * 11 aug 06 david vallado
184
+ * chg lyddane choice back to strn3, constants, misc doc
185
+ * 15 dec 05 david vallado
186
+ * misc fixes
187
+ * 26 jul 05 david vallado
188
+ * fixes for paper
189
+ * note that each fix is preceded by a
190
+ * comment with "sgp4fix" and an explanation of
191
+ * what was changed
192
+ * 10 aug 04 david vallado
193
+ * 2nd printing baseline working
194
+ * 14 may 01 david vallado
195
+ * 2nd edition baseline
196
+ * 80 norad
197
+ * original baseline
198
+ * ----------------------------------------------------------------
199
+ */
200
+ export class Sgp4 {
201
+ /*
202
+ * -----------------------------------------------------------------------------
203
+ *
204
+ * procedure angle_SGP4
205
+ *
206
+ * this procedure calculates the angle between two vectors. the output is
207
+ * set to 999999.1 to indicate an undefined value. be sure to check for
208
+ * this at the output phase.
209
+ *
210
+ * author : david vallado 719-573-2600 1 mar 2001
211
+ *
212
+ * inputs description range / units
213
+ * vec1 - vector number 1
214
+ * vec2 - vector number 2
215
+ *
216
+ * outputs :
217
+ * theta - angle between the two vectors -pi to pi
218
+ *
219
+ * locals :
220
+ * temp - temporary real variable
221
+ *
222
+ * coupling :
223
+ * dot dot product of two vectors
224
+ * ---------------------------------------------------------------------------
225
+ */
226
+ private static angle_(vec1: Vec3Flat, vec2: Vec3Flat): number {
227
+ const small = 0.00000001;
228
+ const unknown = 999999.1; /** Ootk -- original 'undefined' is protected in JS */
229
+
230
+ const magv1 = Sgp4.mag_(vec1);
231
+ const magv2 = Sgp4.mag_(vec2);
232
+
233
+ const magnitudeProduct = magv1 * magv2;
234
+
235
+ if (magnitudeProduct > small * small) {
236
+ let temp = Sgp4.dot_(vec1, vec2) / (magnitudeProduct);
237
+
238
+ // Clamp to [-1, 1] to avoid NaN from floating point errors
239
+ if (temp > 1.0) {
240
+ temp = 1.0;
241
+ }
242
+
243
+ if (temp < -1.0) {
244
+ temp = -1.0;
245
+ }
246
+
247
+ return Math.acos(temp);
248
+ }
249
+
250
+ return unknown;
251
+ }
252
+
253
+ /*
254
+ * -----------------------------------------------------------------------------
255
+ *
256
+ * function asinh_SGP4
257
+ *
258
+ * this function evaluates the inverse hyperbolic sine function.
259
+ *
260
+ * author : david vallado 719-573-2600 1 mar 2001
261
+ *
262
+ * inputs description range / units
263
+ * xval - angle value any real
264
+ *
265
+ * outputs :
266
+ * arcsinh - result any real
267
+ *
268
+ * locals :
269
+ * none.
270
+ *
271
+ * coupling :
272
+ * none.
273
+ * ---------------------------------------------------------------------------
274
+ */
275
+ private static asinh_(xval: number): number {
276
+ return Math.log(xval + Math.sqrt(xval * xval + 1.0));
277
+ }
278
+
279
+ /*
280
+ * -----------------------------------------------------------------------------
281
+ *
282
+ * function twoline2rv
283
+ *
284
+ * this function converts the two line element set character string data to
285
+ * variables and initializes the sgp4 variables. several intermediate varaibles
286
+ * and quantities are determined. note that the result is a structure so multiple
287
+ * satellites can be processed simultaneously without having to reinitialize. the
288
+ * verification mode is an important option that permits quick checks of any
289
+ * changes to the underlying technical theory. this option works using a
290
+ * modified tle file in which the start, stop, and delta time values are
291
+ * included at the end of the second line of data. this only works with the
292
+ * verification mode. the catalog mode simply propagates from -1440 to 1440 min
293
+ * from epoch and is useful when performing entire catalog runs.
294
+ *
295
+ * author : david vallado 719-573-2600 1 mar 2001
296
+ *
297
+ * inputs :
298
+ * longstr1 - first line of the tle
299
+ * longstr2 - second line of the tle
300
+ * typerun - type of run verification 'v', catalog 'c',
301
+ * manual 'm'
302
+ * typeinput - type of manual input mfe 'm', epoch 'e', dayofyr 'd'
303
+ * opsmode - mode of operation afspc or improved 'a', 'i'
304
+ * whichconst - which set of constants to use 72, 84
305
+ *
306
+ * outputs :
307
+ * satrec - structure containing all the sgp4 satellite information
308
+ *
309
+ * coupling :
310
+ * getgravconst-
311
+ * days2mdhms - conversion of days to month, day, hour, minute, second
312
+ * jday - convert day month year hour minute second into julian date
313
+ * sgp4init - initialize the sgp4 variables
314
+ *
315
+ * references :
316
+ * norad spacetrack report #3
317
+ * vallado, crawford, hujsak, kelso 2006
318
+ * ---------------------------------------------------------------------------
319
+ */
320
+ static createSatrec(
321
+ tleLine1: string,
322
+ tleLine2: string,
323
+ whichconst = Sgp4GravConstants.wgs72,
324
+ opsmode = Sgp4OpsMode.IMPROVED,
325
+ ): SatelliteRecord {
326
+ let year = 0;
327
+
328
+ const satrec = {
329
+ error: Sgp4ErrorCode.NO_ERROR,
330
+ } as SatelliteRecord;
331
+
332
+ /*
333
+ * Sgp4fix no longer needed
334
+ * getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
335
+ */
336
+ const xpdotp = 1440.0 / (2.0 * PI); // 229.1831180523293;
337
+
338
+ satrec.satnum = tleLine1.substring(2, 7);
339
+
340
+ satrec.epochyr = parseInt(tleLine1.substring(18, 20));
341
+ satrec.epochdays = parseFloat(tleLine1.substring(20, 32));
342
+ satrec.ndot = parseFloat(tleLine1.substring(33, 43));
343
+ satrec.nddot = parseFloat(
344
+ `${tleLine1.substring(44, 45)}.${tleLine1.substring(45, 50)}E${tleLine1.substring(50, 52)}`,
345
+ );
346
+ satrec.bstar = parseFloat(
347
+ `${tleLine1.substring(53, 54)}.${tleLine1.substring(54, 59)}E${tleLine1.substring(59, 61)}`,
348
+ );
349
+
350
+ satrec.inclo = parseFloat(tleLine2.substring(8, 16));
351
+ satrec.nodeo = parseFloat(tleLine2.substring(17, 25));
352
+ satrec.ecco = parseFloat(`.${tleLine2.substring(26, 33)}`);
353
+ satrec.argpo = parseFloat(tleLine2.substring(34, 42));
354
+ satrec.mo = parseFloat(tleLine2.substring(43, 51));
355
+ satrec.no = parseFloat(tleLine2.substring(52, 63));
356
+
357
+ // ---- find no, ndot, nddot ----
358
+ satrec.no /= xpdotp; // Rad/min
359
+ /** Ootk -- nexp and ibexp are calculated above using template literals */
360
+ /*
361
+ * Satrec.nddot = satrec.nddot * Math.pow(10.0, nexp);
362
+ * satrec.bstar = satrec.bstar * Math.pow(10.0, ibexp);
363
+ */
364
+
365
+ /*
366
+ * ---- convert to sgp4 units ----
367
+ * satrec.a = (satrec.no * tumin) ** (-2.0 / 3.0);
368
+ */
369
+ /** Ootk -- Not sure why the following two lines are added. 1st and 2nd derivatives aren't even used anymore */
370
+ /*
371
+ * Satrec.ndot /= xpdotp * 1440.0; // ? * minperday
372
+ * satrec.nddot /= xpdotp * 1440.0 * 1440;
373
+ */
374
+
375
+ // ---- find standard orbital elements ----
376
+ satrec.inclo *= DEG2RAD;
377
+ satrec.nodeo *= DEG2RAD;
378
+ satrec.argpo *= DEG2RAD;
379
+ satrec.mo *= DEG2RAD;
380
+
381
+ /*
382
+ * Sgp4fix not needed here
383
+ * satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0;
384
+ * satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0;
385
+ */
386
+
387
+ /*
388
+ * ----------------------------------------------------------------
389
+ * find sgp4epoch time of element set
390
+ * remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
391
+ * and minutes from the epoch (time)
392
+ * ----------------------------------------------------------------
393
+ */
394
+
395
+ /*
396
+ * ---------------- temp fix for years from 1957-2056 -------------------
397
+ * --------- correct fix will occur when year is 4-digit in tle ---------
398
+ */
399
+
400
+ if (satrec.epochyr < 57) {
401
+ year = satrec.epochyr + 2000;
402
+ } else {
403
+ year = satrec.epochyr + 1900;
404
+ }
405
+
406
+ const { mon, day, hr, min, sec } = Sgp4.days2mdhms(year, satrec.epochdays);
407
+
408
+ const jdayRes = Sgp4.jday(year, mon, day, hr, min, sec);
409
+
410
+ satrec.jdsatepoch = jdayRes.jd + jdayRes.jdFrac;
411
+
412
+ // ---------------- initialize the orbit at sgp4epoch -------------------
413
+ Sgp4.sgp4init_(satrec as unknown as SatelliteRecord, {
414
+ whichconst,
415
+ opsmode,
416
+ satn: satrec.satnum,
417
+ epoch: satrec.jdsatepoch - 2433281.5,
418
+ xbstar: satrec.bstar,
419
+ xecco: satrec.ecco,
420
+ xargpo: satrec.argpo,
421
+ xinclo: satrec.inclo,
422
+ xndot: satrec.ndot,
423
+ xnddot: satrec.nddot,
424
+ xmo: satrec.mo,
425
+ xno: satrec.no,
426
+ xnodeo: satrec.nodeo,
427
+ });
428
+
429
+ return satrec as unknown as SatelliteRecord;
430
+ }
431
+
432
+ static createSatrecFromOmm(
433
+ omm: OmmParsedDataFormat,
434
+ whichconst = Sgp4GravConstants.wgs72,
435
+ opsmode = Sgp4OpsMode.IMPROVED,
436
+ ): SatelliteRecord {
437
+ let year = 0;
438
+
439
+ const satrec = {
440
+ error: Sgp4ErrorCode.NO_ERROR,
441
+ } as SatelliteRecord;
442
+
443
+ const xpdotp = 1440.0 / (2.0 * PI); // 229.1831180523293;
444
+
445
+ satrec.error = Sgp4ErrorCode.NO_ERROR;
446
+
447
+ satrec.satnum = omm.NORAD_CAT_ID;
448
+
449
+ satrec.epochyr = parseInt(omm.epoch.year.toString().slice(-2));
450
+ satrec.epochdays = omm.epoch.doy;
451
+ satrec.ndot = parseFloat(omm.MEAN_MOTION_DOT);
452
+ satrec.nddot = parseFloat(omm.MEAN_MOTION_DDOT);
453
+ satrec.bstar = parseFloat(omm.BSTAR);
454
+ satrec.inclo = parseFloat(omm.INCLINATION);
455
+ satrec.nodeo = parseFloat(omm.RA_OF_ASC_NODE);
456
+ satrec.ecco = parseFloat(omm.ECCENTRICITY);
457
+ satrec.argpo = parseFloat(omm.ARG_OF_PERICENTER);
458
+ satrec.mo = parseFloat(omm.MEAN_ANOMALY);
459
+ satrec.no = parseFloat(omm.MEAN_MOTION);
460
+
461
+ // ---- find no, ndot, nddot ----
462
+ satrec.no /= xpdotp; // Rad/min
463
+ /** Ootk -- nexp and ibexp are calculated above using template literals */
464
+ /*
465
+ * Satrec.nddot = satrec.nddot * Math.pow(10.0, nexp);
466
+ * satrec.bstar = satrec.bstar * Math.pow(10.0, ibexp);
467
+ */
468
+
469
+ /*
470
+ * ---- convert to sgp4 units ----
471
+ * satrec.a = (satrec.no * tumin) ** (-2.0 / 3.0);
472
+ */
473
+ /** Ootk -- Not sure why the following two lines are added. 1st and 2nd derivatives aren't even used anymore */
474
+ /*
475
+ * Satrec.ndot /= xpdotp * 1440.0; // ? * minperday
476
+ * satrec.nddot /= xpdotp * 1440.0 * 1440;
477
+ */
478
+
479
+ // ---- find standard orbital elements ----
480
+ satrec.inclo *= DEG2RAD;
481
+ satrec.nodeo *= DEG2RAD;
482
+ satrec.argpo *= DEG2RAD;
483
+ satrec.mo *= DEG2RAD;
484
+
485
+ /*
486
+ * Sgp4fix not needed here
487
+ * satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0;
488
+ * satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0;
489
+ */
490
+
491
+ /*
492
+ * ----------------------------------------------------------------
493
+ * find sgp4epoch time of element set
494
+ * remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
495
+ * and minutes from the epoch (time)
496
+ * ----------------------------------------------------------------
497
+ */
498
+
499
+ /*
500
+ * ---------------- temp fix for years from 1957-2056 -------------------
501
+ * --------- correct fix will occur when year is 4-digit in tle ---------
502
+ */
503
+
504
+ if (satrec.epochyr < 57) {
505
+ year = satrec.epochyr + 2000;
506
+ } else {
507
+ year = satrec.epochyr + 1900;
508
+ }
509
+
510
+ const { mon, day, hr, min, sec } = Sgp4.days2mdhms(year, satrec.epochdays);
511
+
512
+ const jdayRes = Sgp4.jday(year, mon, day, hr, min, sec);
513
+
514
+ satrec.jdsatepoch = jdayRes.jd + jdayRes.jdFrac;
515
+
516
+ // ---------------- initialize the orbit at sgp4epoch -------------------
517
+ Sgp4.sgp4init_(satrec as unknown as SatelliteRecord, {
518
+ whichconst,
519
+ opsmode,
520
+ satn: satrec.satnum,
521
+ epoch: satrec.jdsatepoch - 2433281.5,
522
+ xbstar: satrec.bstar,
523
+ xecco: satrec.ecco,
524
+ xargpo: satrec.argpo,
525
+ xinclo: satrec.inclo,
526
+ xndot: satrec.ndot,
527
+ xnddot: satrec.nddot,
528
+ xmo: satrec.mo,
529
+ xno: satrec.no,
530
+ xnodeo: satrec.nodeo,
531
+ });
532
+
533
+ return satrec as unknown as SatelliteRecord;
534
+ }
535
+
536
+ /*
537
+ * -----------------------------------------------------------------------------
538
+ *
539
+ * procedure cross_SGP4
540
+ *
541
+ * this procedure crosses two vectors.
542
+ *
543
+ * author : david vallado 719-573-2600 1 mar 2001
544
+ *
545
+ * inputs description range / units
546
+ * vec1 - vector number 1
547
+ * vec2 - vector number 2
548
+ *
549
+ * outputs :
550
+ * outvec - vector result of a x b
551
+ *
552
+ * locals :
553
+ * none.
554
+ *
555
+ * coupling :
556
+ * mag magnitude of a vector
557
+ * ----------------------------------------------------------------------------
558
+ */
559
+ private static cross_(vec1: Vec3Flat, vec2: Vec3Flat): Vec3Flat {
560
+ return [
561
+ vec1[1] * vec2[2] - vec1[2] * vec2[1],
562
+ vec1[2] * vec2[0] - vec1[0] * vec2[2],
563
+ vec1[0] * vec2[1] - vec1[1] * vec2[0],
564
+ ];
565
+ }
566
+
567
+ /*
568
+ * -----------------------------------------------------------------------------
569
+ *
570
+ * procedure days2mdhms
571
+ *
572
+ * this procedure converts the day of the year, days, to the equivalent month
573
+ * day, hour, minute and second.
574
+ *
575
+ * algorithm : set up array for the number of days per month
576
+ * find leap year - use 1900 because 2000 is a leap year
577
+ * loop through a temp value while the value is < the days
578
+ * perform int conversions to the correct day and month
579
+ * convert remainder into h m s using type conversions
580
+ *
581
+ * author : david vallado 719-573-2600 1 mar 2001
582
+ *
583
+ * inputs description range / units
584
+ * year - year 1900 .. 2100
585
+ * days - julian day of the year 0.0 .. 366.0
586
+ *
587
+ * outputs :
588
+ * mon - month 1 .. 12
589
+ * day - day 1 .. 28,29,30,31
590
+ * hr - hour 0 .. 23
591
+ * min - minute 0 .. 59
592
+ * sec - second 0.0 .. 59.999
593
+ *
594
+ * locals :
595
+ * dayofyr - day of year
596
+ * temp - temporary extended values
597
+ * inttemp - temporary int value
598
+ * i - index
599
+ * lmonth[13] - int array containing the number of days per month
600
+ *
601
+ * coupling :
602
+ * none.
603
+ * ---------------------------------------------------------------------------
604
+ */
605
+ static days2mdhms(
606
+ year: number,
607
+ days: number,
608
+ ): {
609
+ mon: number;
610
+ day: number;
611
+ hr: number;
612
+ min: number;
613
+ sec: number;
614
+ } {
615
+ const lmonth = [31, year % 4 === 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
616
+
617
+ const dayofyr = Math.floor(days);
618
+
619
+ // ----------------- find month and day of month ----------------
620
+ /** Ootk -- Incorporated in the above declaration */
621
+ /*
622
+ * If ((year % 4) == 0)
623
+ * lmonth[2] = 29;
624
+ */
625
+
626
+ let i = 1;
627
+ let inttemp = 0;
628
+
629
+ while (dayofyr > inttemp + (lmonth[i - 1] as number) && i < 12) {
630
+ inttemp += (lmonth[i - 1] as number);
631
+ i += 1;
632
+ }
633
+
634
+ const mon = i;
635
+ const day = dayofyr - inttemp;
636
+
637
+ // ----------------- find hours minutes and seconds -------------
638
+ let temp = (days - dayofyr) * 24.0;
639
+ const hr = Math.floor(temp);
640
+
641
+ temp = (temp - hr) * 60.0;
642
+ const min = Math.floor(temp);
643
+ const sec = (temp - min) * 60.0;
644
+
645
+ return {
646
+ mon,
647
+ day,
648
+ hr,
649
+ min,
650
+ sec,
651
+ };
652
+ }
653
+
654
+ /*
655
+ * -----------------------------------------------------------------------------
656
+ *
657
+ * function dot_SGP4
658
+ *
659
+ * this function finds the dot product of two vectors.
660
+ *
661
+ * author : david vallado 719-573-2600 1 mar 2001
662
+ *
663
+ * inputs description range / units
664
+ * vec1 - vector number 1
665
+ * vec2 - vector number 2
666
+ *
667
+ * outputs :
668
+ * dot - result
669
+ *
670
+ * locals :
671
+ * none.
672
+ *
673
+ * coupling :
674
+ * none.
675
+ * ---------------------------------------------------------------------------
676
+ */
677
+ private static dot_(v1: Vec3Flat, v2: Vec3Flat): number {
678
+ return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
679
+ }
680
+
681
+ /*
682
+ * -----------------------------------------------------------------------------
683
+ *
684
+ * function gstime
685
+ *
686
+ * this function finds the greenwich sidereal time.
687
+ *
688
+ * author : david vallado 719-573-2600 1 mar 2001
689
+ *
690
+ * inputs description range / units
691
+ * jdut1 - julian date in ut1 days from 4713 bc
692
+ *
693
+ * outputs :
694
+ * gstime - greenwich sidereal time 0 to 2PI rad
695
+ *
696
+ * locals :
697
+ * temp - temporary variable for doubles rad
698
+ * tut1 - julian centuries from the
699
+ * jan 1, 2000 12 h epoch (ut1)
700
+ *
701
+ * coupling :
702
+ * none
703
+ *
704
+ * references :
705
+ * vallado 2004, 191, eq 3-45
706
+ * ---------------------------------------------------------------------------
707
+ */
708
+ static gstime(jdut1: number): GreenwichMeanSiderealTime {
709
+ const tut1 = (jdut1 - 2451545.0) / 36525.0;
710
+
711
+ let temp =
712
+ -6.2e-6 * tut1 * tut1 * tut1 + 0.093104 * tut1 * tut1 +
713
+ (876600.0 * 3600 + 8640184.812866) * tut1 + 67310.54841; // Sec
714
+
715
+ temp = ((temp * DEG2RAD) / 240.0) % TAU; // 360/86400 = 1/240, to deg, to rad
716
+
717
+ // ------------------------ check quadrants ---------------------
718
+ if (temp < 0.0) {
719
+ temp += TAU;
720
+ }
721
+
722
+ return temp as GreenwichMeanSiderealTime;
723
+ }
724
+
725
+ /*
726
+ * -----------------------------------------------------------------------------
727
+ *
728
+ * procedure invjday
729
+ *
730
+ * this procedure finds the year, month, day, hour, minute and second
731
+ * given the julian date. tu can be ut1, tdt, tdb, etc.
732
+ *
733
+ * algorithm : set up starting values
734
+ * find leap year - use 1900 because 2000 is a leap year
735
+ * find the elapsed days through the year in a loop
736
+ * call routine to find each individual value
737
+ *
738
+ * author : david vallado 719-573-2600 1 mar 2001
739
+ *
740
+ * inputs description range / units
741
+ * jd - julian date days from 4713 bc
742
+ * jdfrac - julian date fraction into day days from 4713 bc
743
+ *
744
+ * outputs :
745
+ * year - year 1900 .. 2100
746
+ * mon - month 1 .. 12
747
+ * day - day 1 .. 28,29,30,31
748
+ * hr - hour 0 .. 23
749
+ * min - minute 0 .. 59
750
+ * sec - second 0.0 .. 59.999
751
+ *
752
+ * locals :
753
+ * days - day of year plus fractional
754
+ * portion of a day days
755
+ * tu - julian centuries from 0 h
756
+ * jan 0, 1900
757
+ * temp - temporary double values
758
+ * leapyrs - number of leap years from 1900
759
+ *
760
+ * coupling :
761
+ * days2mdhms - finds month, day, hour, minute and second given days and year
762
+ *
763
+ * references :
764
+ * vallado 2013, 203, alg 22, ex 3-13
765
+ * ---------------------------------------------------------------------------
766
+ */
767
+ static invjday(
768
+ jd: number,
769
+ jdfrac: number,
770
+ ): { year: number; mon: number; day: number; hr: number; min: number; sec: number } {
771
+ let leapyrs;
772
+ let days;
773
+
774
+ // Check jdfrac for multiple days
775
+ if (Math.abs(jdfrac) >= 1.0) {
776
+ jd += Math.floor(jdfrac);
777
+ jdfrac -= Math.floor(jdfrac);
778
+ }
779
+
780
+ // Check for fraction of a day included in the jd
781
+ const dt = jd - Math.floor(jd) - 0.5;
782
+
783
+ if (Math.abs(dt) > 0.00000001) {
784
+ jd -= dt;
785
+ jdfrac += dt;
786
+ }
787
+
788
+ /* --------------- find year and days of the year --------------- */
789
+ const temp = jd - 2415019.5;
790
+ const tu = temp / 365.25;
791
+ let year = 1900 + Math.floor(tu);
792
+
793
+ leapyrs = Math.floor((year - 1901) * 0.25);
794
+
795
+ days = Math.floor(temp - ((year - 1900) * 365.0 + leapyrs));
796
+
797
+ /* ------------ check for case of beginning of a year ----------- */
798
+ if (days + jdfrac < 1.0) {
799
+ year -= 1;
800
+ leapyrs = Math.floor((year - 1901) * 0.25);
801
+ days = Math.floor(temp - ((year - 1900) * 365.0 + leapyrs));
802
+ }
803
+
804
+ /* ----------------- find remaining data ------------------------- */
805
+ const { mon, day, hr, min, sec } = Sgp4.days2mdhms(year, days + jdfrac);
806
+
807
+ return {
808
+ year,
809
+ mon,
810
+ day,
811
+ hr,
812
+ min,
813
+ sec,
814
+ };
815
+ }
816
+
817
+ /*
818
+ * -----------------------------------------------------------------------------
819
+ *
820
+ * procedure jday
821
+ *
822
+ * this procedure finds the julian date given the year, month, day, and time.
823
+ * the julian date is defined by each elapsed day since noon, jan 1, 4713 bc.
824
+ *
825
+ * algorithm : calculate the answer in one step for efficiency
826
+ *
827
+ * author : david vallado 719-573-2600 1 mar 2001
828
+ *
829
+ * inputs description range / units
830
+ * year - year 1900 .. 2100
831
+ * mon - month 1 .. 12
832
+ * day - day 1 .. 28,29,30,31
833
+ * hr - universal time hour 0 .. 23
834
+ * min - universal time min 0 .. 59
835
+ * sec - universal time sec 0.0 .. 59.999
836
+ *
837
+ * outputs :
838
+ * jd - julian date days from 4713 bc
839
+ * jdfrac - julian date fraction into day days from 4713 bc
840
+ *
841
+ * locals :
842
+ * none.
843
+ *
844
+ * coupling :
845
+ * none.
846
+ *
847
+ * references :
848
+ * vallado 2013, 183, alg 14, ex 3-4
849
+ *
850
+ * ---------------------------------------------------------------------------
851
+ */
852
+ static jday(year: number | Date, mon = 0, day = 0, hr = 0, min = 0, sec = 0, ms = 0): { jd: number; jdFrac: number } {
853
+ if (year instanceof Date) {
854
+ mon = year.getUTCMonth() + 1;
855
+ day = year.getUTCDate();
856
+ hr = year.getUTCHours();
857
+ min = year.getUTCMinutes();
858
+ sec = year.getUTCSeconds();
859
+ ms = year.getUTCMilliseconds();
860
+ year = year.getUTCFullYear();
861
+ }
862
+
863
+ let jd =
864
+ 367.0 * year -
865
+ Math.floor(7 * (year + Math.floor((mon + 9) / 12.0)) * 0.25) +
866
+ Math.floor((275 * mon) / 9.0) +
867
+ day +
868
+ 1721013.5; // Use - 678987.0 to go to mjd directly
869
+ let jdFrac = (ms / 1000 + sec + min * 60.0 + hr * 3600.0) / 86400.0;
870
+
871
+ // Check that the day and fractional day are correct
872
+ if (Math.abs(jdFrac) > 1.0) {
873
+ const dtt = Math.floor(jdFrac);
874
+
875
+ jd += dtt;
876
+ jdFrac -= dtt;
877
+ }
878
+ // - 0.5*sgn(100.0*year + mon - 190002.5) + 0.5;
879
+
880
+ return { jd, jdFrac };
881
+ }
882
+
883
+ /*
884
+ * -----------------------------------------------------------------------------
885
+ *
886
+ * function mag
887
+ *
888
+ * this procedure finds the magnitude of a vector.
889
+ *
890
+ * author : david vallado 719-573-2600 1 mar 2001
891
+ *
892
+ * inputs description range / units
893
+ * vec - vector
894
+ *
895
+ * outputs :
896
+ * mag - answer
897
+ *
898
+ * locals :
899
+ * none.
900
+ *
901
+ * coupling :
902
+ * none.
903
+ * ---------------------------------------------------------------------------
904
+ */
905
+ private static mag_(v: Vec3Flat): number {
906
+ return Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
907
+ }
908
+
909
+ /*
910
+ * -----------------------------------------------------------------------------
911
+ *
912
+ * function newtonnu_SGP4
913
+ *
914
+ * this function solves keplers equation when the true anomaly is known.
915
+ * the mean and eccentric, parabolic, or hyperbolic anomaly is also found.
916
+ * the parabolic limit at 168ø is arbitrary. the hyperbolic anomaly is also
917
+ * limited. the hyperbolic sine is used because it's not double valued.
918
+ *
919
+ * author : david vallado 719-573-2600 27 may 2002
920
+ *
921
+ * revisions
922
+ * vallado - fix small 24 sep 2002
923
+ *
924
+ * inputs description range / units
925
+ * ecc - eccentricity 0.0 to
926
+ * nu - true anomaly -2pi to 2pi rad
927
+ *
928
+ * outputs :
929
+ * e0 - eccentric anomaly 0.0 to 2pi rad 153.02 ø
930
+ * m - mean anomaly 0.0 to 2pi rad 151.7425 ø
931
+ *
932
+ * locals :
933
+ * e1 - eccentric anomaly, next value rad
934
+ * sine - sine of e
935
+ * cose - cosine of e
936
+ * ktr - index
937
+ *
938
+ * coupling :
939
+ * asinh - arc hyperbolic sine
940
+ *
941
+ * references :
942
+ * vallado 2013, 77, alg 5
943
+ * ---------------------------------------------------------------------------
944
+ */
945
+ private static newtonnu_(
946
+ ecc: number,
947
+ nu: number,
948
+ ): {
949
+ e0: number;
950
+ m: number;
951
+ } {
952
+ // --------------------- implementation ---------------------
953
+ let e0 = 999999.9;
954
+ let m = 999999.9;
955
+ const small = 0.00000001;
956
+
957
+ if (Math.abs(ecc) < small) {
958
+ // --------------------------- circular ------------------------
959
+ m = nu;
960
+ e0 = nu;
961
+ } else if (ecc < 1.0 - small) {
962
+ // ---------------------- elliptical -----------------------
963
+ const sine = (Math.sqrt(1.0 - ecc * ecc) * Math.sin(nu)) / (1.0 + ecc * Math.cos(nu));
964
+ const cose = (ecc + Math.cos(nu)) / (1.0 + ecc * Math.cos(nu));
965
+
966
+ e0 = Math.atan2(sine, cose);
967
+ m = e0 - ecc * Math.sin(e0);
968
+ } else if (ecc > 1.0 + small) {
969
+ // -------------------- hyperbolic --------------------
970
+ if (ecc > 1.0 && Math.abs(nu) + 0.00001 < PI - Math.acos(1.0 / ecc)) {
971
+ const sine = (Math.sqrt(ecc * ecc - 1.0) * Math.sin(nu)) / (1.0 + ecc * Math.cos(nu));
972
+
973
+ e0 = Sgp4.asinh_(sine);
974
+ m = ecc * Sgp4.sinh_(e0) - e0;
975
+ }
976
+ } else if (Math.abs(nu) < (168.0 * PI) / 180.0) {
977
+ // ----------------- parabolic ---------------------
978
+ e0 = Math.tan(nu * 0.5);
979
+ m = e0 + (e0 * e0 * e0) / 3.0;
980
+ }
981
+
982
+ if (ecc < 1.0) {
983
+ m %= 2.0 * PI;
984
+ if (m < 0.0) {
985
+ m += 2.0 * PI;
986
+ }
987
+ e0 %= 2.0 * PI;
988
+ }
989
+
990
+ return {
991
+ e0,
992
+ m,
993
+ };
994
+ }
995
+
996
+ /*
997
+ *----------------------------------------------------------------------------
998
+ *
999
+ * procedure sgp4
1000
+ *
1001
+ * this procedure is the sgp4 prediction model from space command. this is an
1002
+ * updated and combined version of sgp4 and sdp4, which were originally
1003
+ * published separately in spacetrack report //3. this version follows the
1004
+ * methodology from the aiaa paper (2006) describing the history and
1005
+ * development of the code.
1006
+ *
1007
+ * author : david vallado 719-573-2600 28 jun 2005
1008
+ *
1009
+ * inputs :
1010
+ * satrec - initialised structure from sgp4init() call.
1011
+ * tsince - time since epoch (minutes)
1012
+ *
1013
+ * outputs :
1014
+ * r - position vector km
1015
+ * v - velocity km/sec
1016
+ * return code - non-zero on error.
1017
+ * 1 - mean elements, ecc >= 1.0 or ecc < -0.001 or a < 0.95 er
1018
+ * 2 - mean motion less than 0.0
1019
+ * 3 - pert elements, ecc < 0.0 or ecc > 1.0
1020
+ * 4 - semi-latus rectum < 0.0
1021
+ * 5 - epoch elements are sub-orbital
1022
+ * 6 - satellite has decayed
1023
+ *
1024
+ * locals :
1025
+ * am -
1026
+ * axnl, aynl -
1027
+ * betal -
1028
+ * cosim , sinim , cosomm , sinomm , cnod , snod , cos2u ,
1029
+ * sin2u , coseo1 , sineo1 , cosi , sini , cosip , sinip ,
1030
+ * cosisq , cossu , sinsu , cosu , sinu
1031
+ * delm -
1032
+ * delomg -
1033
+ * dndt -
1034
+ * eccm -
1035
+ * emsq -
1036
+ * ecose -
1037
+ * el2 -
1038
+ * eo1 -
1039
+ * eccp -
1040
+ * esine -
1041
+ * argpm -
1042
+ * argpp -
1043
+ * omgadf -
1044
+ * pl -
1045
+ * r -
1046
+ * rtemsq -
1047
+ * rdotl -
1048
+ * rl -
1049
+ * rvdot -
1050
+ * rvdotl -
1051
+ * su -
1052
+ * t2 , t3 , t4 , tc
1053
+ * tem5, temp , temp1 , temp2 , tempa , tempe , templ
1054
+ * u , ux , uy , uz , vx , vy , vz
1055
+ * inclm - inclination
1056
+ * mm - mean anomaly
1057
+ * nm - mean motion
1058
+ * nodem - right asc of ascending node
1059
+ * xinc -
1060
+ * xincp -
1061
+ * xl -
1062
+ * xlm -
1063
+ * mp -
1064
+ * xmdf -
1065
+ * xmx -
1066
+ * xmy -
1067
+ * nodedf -
1068
+ * xnode -
1069
+ * nodep -
1070
+ * np -
1071
+ *
1072
+ * coupling :
1073
+ * getgravconst-
1074
+ * dpper
1075
+ * dspace
1076
+ *
1077
+ * references :
1078
+ * hoots, roehrich, norad spacetrack report //3 1980
1079
+ * hoots, norad spacetrack report //6 1986
1080
+ * hoots, schumacher and glover 2004
1081
+ * vallado, crawford, hujsak, kelso 2006
1082
+ *----------------------------------------------------------------------------
1083
+ */
1084
+ static propagate(satrec: SatelliteRecord, tsince: number): StateVectorSgp4 {
1085
+ /* ------------------ set mathematical constants --------------- */
1086
+ /*
1087
+ * Sgp4fix divisor for divide by zero check on inclination
1088
+ * the old check used 1.0 + cos(PI-1.0e-9), but then compared it to
1089
+ * 1.5 e-12, so the threshold was changed to 1.5e-12 for consistency
1090
+ */
1091
+
1092
+ /*
1093
+ * Sgp4fix identify constants and allow alternate values
1094
+ * getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
1095
+ */
1096
+ const { xke, j2, j3oj2, vkmpersec } = satrec;
1097
+
1098
+ // --------------------- clear sgp4 error flag -----------------
1099
+ satrec.t = tsince;
1100
+ satrec.error = Sgp4ErrorCode.NO_ERROR;
1101
+
1102
+ // ------- update for secular gravity and atmospheric drag -----
1103
+ const xmdf = satrec.mo + satrec.mdot * satrec.t;
1104
+ const argpdf = satrec.argpo + satrec.argpdot * satrec.t;
1105
+ const nodedf = satrec.nodeo + satrec.nodedot * satrec.t;
1106
+ let argpm = argpdf;
1107
+ let mm = xmdf;
1108
+ const t2 = satrec.t * satrec.t;
1109
+ let nodem = nodedf + satrec.nodecf * t2;
1110
+ let tempa = 1.0 - satrec.cc1 * satrec.t;
1111
+ let tempe = satrec.bstar * satrec.cc4 * satrec.t;
1112
+ let templ = satrec.t2cof * t2;
1113
+
1114
+ if (!satrec.isimp) {
1115
+ const delomg = satrec.omgcof * satrec.t;
1116
+ // Sgp4fix use mutliply for speed instead of pow
1117
+ const delmtemp = 1.0 + satrec.eta * Math.cos(xmdf);
1118
+ const delm = satrec.xmcof * (delmtemp * delmtemp * delmtemp - satrec.delmo);
1119
+ const temp = delomg + delm;
1120
+
1121
+ mm = xmdf + temp;
1122
+ argpm = argpdf - temp;
1123
+ const t3 = t2 * satrec.t;
1124
+ const t4 = t3 * satrec.t;
1125
+
1126
+ tempa = tempa - satrec.d2 * t2 - satrec.d3 * t3 - satrec.d4 * t4;
1127
+ tempe += satrec.bstar * satrec.cc5 * (Math.sin(mm) - satrec.sinmao);
1128
+ templ = templ + satrec.t3cof * t3 + t4 * (satrec.t4cof + satrec.t * satrec.t5cof);
1129
+ }
1130
+
1131
+ let nm = satrec.no;
1132
+ let em = satrec.ecco;
1133
+ let inclm = satrec.inclo;
1134
+
1135
+ if (satrec.method === Sgp4Methods.DEEP_SPACE) {
1136
+ [em, argpm, inclm, mm, nodem, nm] = Sgp4.dspace_(
1137
+ em,
1138
+ argpm,
1139
+ inclm,
1140
+ mm,
1141
+ nodem,
1142
+ nm,
1143
+ satrec,
1144
+ );
1145
+ }
1146
+
1147
+ if (nm <= 0.0) {
1148
+ satrec.error = Sgp4ErrorCode.MEAN_MOTION_NEGATIVE;
1149
+
1150
+ return { position: false, velocity: false };
1151
+ }
1152
+
1153
+ const am = (xke / nm) ** x2o3 * tempa * tempa;
1154
+
1155
+ nm = xke / am ** 1.5;
1156
+ em -= tempe;
1157
+
1158
+ /*
1159
+ * Fix tolerance for error recognition
1160
+ * sgp4fix am is fixed from the previous nm check
1161
+ */
1162
+ /* istanbul ignore next | This is no longer possible*/
1163
+ if (em >= 1.0 || em < -0.001) {
1164
+ satrec.error = Sgp4ErrorCode.MEAN_MOTION_NEGATIVE;
1165
+
1166
+ return { position: false, velocity: false };
1167
+ }
1168
+
1169
+ // Sgp4fix fix tolerance to avoid a divide by zero
1170
+ if (em < 1.0e-6) {
1171
+ em = 1.0e-6;
1172
+ }
1173
+
1174
+ mm += satrec.no * templ;
1175
+ let xlm = mm + argpm + nodem;
1176
+
1177
+ nodem %= TAU;
1178
+ argpm %= TAU;
1179
+ xlm %= TAU;
1180
+ mm = (xlm - argpm - nodem) % TAU;
1181
+
1182
+ /*
1183
+ * Sgp4fix recover singly averaged mean elements
1184
+ * satrec.am = am;
1185
+ * satrec.em = em;
1186
+ * satrec.im = inclm;
1187
+ * satrec.Om = nodem;
1188
+ * satrec.om = argpm;
1189
+ * satrec.mm = mm;
1190
+ * satrec.nm = nm;
1191
+ */
1192
+
1193
+ // ----------------- compute extra mean quantities -------------
1194
+ const sinim = Math.sin(inclm);
1195
+ const cosim = Math.cos(inclm);
1196
+
1197
+ // -------------------- add lunar-solar periodics --------------
1198
+ let ep = em;
1199
+ let xincp = inclm;
1200
+ let argpp = argpm;
1201
+ let nodep = nodem;
1202
+ let mp = mm;
1203
+ let sinip = sinim;
1204
+ let cosip = cosim;
1205
+
1206
+ if (satrec.method === Sgp4Methods.DEEP_SPACE) {
1207
+ const dpperParameters = {
1208
+ inclo: satrec.inclo,
1209
+ init: false,
1210
+ ep,
1211
+ inclp: xincp,
1212
+ nodep,
1213
+ argpp,
1214
+ mp,
1215
+ opsmode: satrec.operationmode,
1216
+ satrec,
1217
+ };
1218
+
1219
+ ({ ep, nodep, argpp, mp, inclp: xincp } = Sgp4.dpper_(dpperParameters));
1220
+
1221
+ if (xincp < 0.0) {
1222
+ xincp = -xincp;
1223
+ nodep += PI;
1224
+ argpp -= PI;
1225
+ }
1226
+ if (ep < 0.0 || ep > 1.0) {
1227
+ satrec.error = Sgp4ErrorCode.PERT_ELEMENTS_INVALID;
1228
+
1229
+ return { position: false, velocity: false };
1230
+ }
1231
+ }
1232
+
1233
+ // -------------------- long period periodics ------------------
1234
+ if (satrec.method === Sgp4Methods.DEEP_SPACE) {
1235
+ sinip = Math.sin(xincp);
1236
+ cosip = Math.cos(xincp);
1237
+ satrec.aycof = -0.5 * j3oj2 * sinip;
1238
+
1239
+ // Sgp4fix for divide by zero for xincp = 180 deg
1240
+ if (Math.abs(cosip + 1.0) > 1.5e-12) {
1241
+ satrec.xlcof = (-0.25 * j3oj2 * sinip * (3.0 + 5.0 * cosip)) / (1.0 + cosip);
1242
+ } else {
1243
+ satrec.xlcof = (-0.25 * j3oj2 * sinip * (3.0 + 5.0 * cosip)) / temp4;
1244
+ }
1245
+ }
1246
+
1247
+ const axnl = ep * Math.cos(argpp);
1248
+ let temp = 1.0 / (am * (1.0 - ep * ep));
1249
+ const aynl = ep * Math.sin(argpp) + temp * satrec.aycof;
1250
+ const xl = mp + argpp + nodep + temp * satrec.xlcof * axnl;
1251
+
1252
+ // --------------------- solve kepler's equation ---------------
1253
+ const u = (xl - nodep) % TAU;
1254
+ let eo1 = u;
1255
+ let tem5 = 9999.9;
1256
+ let ktr = 1;
1257
+
1258
+ /*
1259
+ * Sgp4fix for kepler iteration
1260
+ * the following iteration needs better limits on corrections
1261
+ */
1262
+ let coseo1 = 0;
1263
+ let sineo1 = 0;
1264
+
1265
+ while (Math.abs(tem5) >= 1.0e-12 && ktr <= 10) {
1266
+ sineo1 = Math.sin(eo1);
1267
+ coseo1 = Math.cos(eo1);
1268
+ tem5 = 1.0 - coseo1 * axnl - sineo1 * aynl;
1269
+ tem5 = (u - aynl * coseo1 + axnl * sineo1 - eo1) / tem5;
1270
+ if (Math.abs(tem5) >= 0.95) {
1271
+ if (tem5 > 0.0) {
1272
+ tem5 = 0.95;
1273
+ } else {
1274
+ tem5 = -0.95;
1275
+ }
1276
+ }
1277
+ eo1 += tem5;
1278
+ ktr += 1;
1279
+ }
1280
+
1281
+ // ------------- short period preliminary quantities -----------
1282
+ const ecose = axnl * coseo1 + aynl * sineo1;
1283
+ const esine = axnl * sineo1 - aynl * coseo1;
1284
+ const el2 = axnl * axnl + aynl * aynl;
1285
+ const pl = am * (1.0 - el2);
1286
+
1287
+ if (pl < 0.0) {
1288
+ satrec.error = Sgp4ErrorCode.SEMI_LATUS_RECTUM_NEGATIVE;
1289
+
1290
+ return { position: false, velocity: false };
1291
+ }
1292
+
1293
+ const rl = am * (1.0 - ecose);
1294
+ const rdotl = (Math.sqrt(am) * esine) / rl;
1295
+ const rvdotl = Math.sqrt(pl) / rl;
1296
+ const betal = Math.sqrt(1.0 - el2);
1297
+
1298
+ temp = esine / (1.0 + betal);
1299
+ const sinu = (am / rl) * (sineo1 - aynl - axnl * temp);
1300
+ const cosu = (am / rl) * (coseo1 - axnl + aynl * temp);
1301
+ let su = Math.atan2(sinu, cosu);
1302
+ const sin2u = (cosu + cosu) * sinu;
1303
+ const cos2u = 1.0 - 2.0 * sinu * sinu;
1304
+
1305
+ temp = 1.0 / pl;
1306
+ const temp1 = 0.5 * j2 * temp;
1307
+ const temp2 = temp1 * temp;
1308
+
1309
+ // -------------- update for short period periodics ------------
1310
+ if (satrec.method === Sgp4Methods.DEEP_SPACE) {
1311
+ const cosisq = cosip * cosip;
1312
+
1313
+ satrec.con41 = 3.0 * cosisq - 1.0;
1314
+ satrec.x1mth2 = 1.0 - cosisq;
1315
+ satrec.x7thm1 = 7.0 * cosisq - 1.0;
1316
+ }
1317
+
1318
+ const mrt = rl * (1.0 - 1.5 * temp2 * betal * satrec.con41) + 0.5 * temp1 * satrec.x1mth2 * cos2u;
1319
+
1320
+ /** Moved this up to reduce unnecessary computation if you are going to return false anyway */
1321
+ // Sgp4fix for decaying satellites
1322
+ if (mrt < 1.0) {
1323
+ satrec.error = Sgp4ErrorCode.SATELLITE_DECAYED;
1324
+
1325
+ return {
1326
+ position: false,
1327
+ velocity: false,
1328
+ };
1329
+ }
1330
+
1331
+ su -= 0.25 * temp2 * satrec.x7thm1 * sin2u;
1332
+ const xnode = nodep + 1.5 * temp2 * cosip * sin2u;
1333
+ const xinc = xincp + 1.5 * temp2 * cosip * sinip * cos2u;
1334
+ const mvt = rdotl - (nm * temp1 * satrec.x1mth2 * sin2u) / xke;
1335
+ const rvdot = rvdotl + (nm * temp1 * (satrec.x1mth2 * cos2u + 1.5 * satrec.con41)) / xke;
1336
+
1337
+ // --------------------- orientation vectors -------------------
1338
+ const sinsu = Math.sin(su);
1339
+ const cossu = Math.cos(su);
1340
+ const snod = Math.sin(xnode);
1341
+ const cnod = Math.cos(xnode);
1342
+ const sini = Math.sin(xinc);
1343
+ const cosi = Math.cos(xinc);
1344
+ const xmx = -snod * cosi;
1345
+ const xmy = cnod * cosi;
1346
+ const ux = xmx * sinsu + cnod * cossu;
1347
+ const uy = xmy * sinsu + snod * cossu;
1348
+ const uz = sini * sinsu;
1349
+ const vx = xmx * cossu - cnod * sinsu;
1350
+ const vy = xmy * cossu - snod * sinsu;
1351
+ const vz = sini * cossu;
1352
+
1353
+ // --------- position and velocity (in km and km/sec) ----------
1354
+ const r = {
1355
+ x: mrt * ux * satrec.radiusearthkm as Kilometers,
1356
+ y: mrt * uy * satrec.radiusearthkm as Kilometers,
1357
+ z: mrt * uz * satrec.radiusearthkm as Kilometers,
1358
+ };
1359
+ const v = {
1360
+ x: (mvt * ux + rvdot * vx) * vkmpersec as KilometersPerSecond,
1361
+ y: (mvt * uy + rvdot * vy) * vkmpersec as KilometersPerSecond,
1362
+ z: (mvt * uz + rvdot * vz) * vkmpersec as KilometersPerSecond,
1363
+ };
1364
+
1365
+ return {
1366
+ position: r,
1367
+ velocity: v,
1368
+ };
1369
+ }
1370
+
1371
+ /*
1372
+ * -----------------------------------------------------------------------------
1373
+ *
1374
+ * function rv2coe_SGP4
1375
+ *
1376
+ * this function finds the classical orbital elements given the geocentric
1377
+ * equatorial position and velocity vectors.
1378
+ *
1379
+ * author : david vallado 719-573-2600 21 jun 2002
1380
+ *
1381
+ * revisions
1382
+ * vallado - fix special cases 5 sep 2002
1383
+ * vallado - delete extra check in inclination code 16 oct 2002
1384
+ * vallado - add constant file use 29 jun 2003
1385
+ * vallado - add mu 2 apr 2007
1386
+ *
1387
+ * inputs description range / units
1388
+ * r - ijk position vector km
1389
+ * v - ijk velocity vector km / s
1390
+ * mu - gravitational parameter km3 / s2
1391
+ *
1392
+ * outputs :
1393
+ * p - semilatus rectum km
1394
+ * a - semimajor axis km
1395
+ * ecc - eccentricity
1396
+ * incl - inclination 0.0 to pi rad
1397
+ * omega - right ascension of ascending node 0.0 to 2pi rad
1398
+ * argp - argument of perigee 0.0 to 2pi rad
1399
+ * nu - true anomaly 0.0 to 2pi rad
1400
+ * m - mean anomaly 0.0 to 2pi rad
1401
+ * arglat - argument of latitude (ci) 0.0 to 2pi rad
1402
+ * truelon - true longitude (ce) 0.0 to 2pi rad
1403
+ * lonper - longitude of periapsis (ee) 0.0 to 2pi rad
1404
+ *
1405
+ * locals :
1406
+ * hbar - angular momentum h vector km2 / s
1407
+ * ebar - eccentricity e vector
1408
+ * nbar - line of nodes n vector
1409
+ * c1 - v**2 - u/r
1410
+ * rdotv - r dot v
1411
+ * hk - hk unit vector
1412
+ * sme - specfic mechanical energy km2 / s2
1413
+ * i - index
1414
+ * e - eccentric, parabolic,
1415
+ * hyperbolic anomaly rad
1416
+ * temp - temporary variable
1417
+ * typeorbit - type of orbit ee, ei, ce, ci
1418
+ *
1419
+ * coupling :
1420
+ * mag - magnitude of a vector
1421
+ * cross - cross product of two vectors
1422
+ * angle - find the angle between two vectors
1423
+ * newtonnu - find the mean anomaly
1424
+ *
1425
+ * references :
1426
+ * vallado 2013, 113, alg 9, ex 2-5
1427
+ * ---------------------------------------------------------------------------
1428
+ */
1429
+ static rv2coe(
1430
+ r: Vec3Flat,
1431
+ v: Vec3Flat,
1432
+ mus: number,
1433
+ ): {
1434
+ p: number;
1435
+ a: number;
1436
+ ecc: number;
1437
+ incl: number;
1438
+ omega: number;
1439
+ argp: number;
1440
+ nu: number;
1441
+ m: number;
1442
+ arglat: number;
1443
+ truelon: number;
1444
+ lonper: number;
1445
+ } {
1446
+ const nbar: Vec3Flat = [0, 0, 0];
1447
+ const ebar: Vec3Flat = [0, 0, 0];
1448
+ let p: number;
1449
+ let a: number;
1450
+ let ecc: number;
1451
+ let incl: number;
1452
+ let omega: number;
1453
+ let argp: number;
1454
+ let nu: number;
1455
+ let m = 0;
1456
+ let arglat: number;
1457
+ let truelon: number;
1458
+ let lonper: number;
1459
+ let rdotv: number;
1460
+ let magn: number;
1461
+ let hk: number;
1462
+ let sme: number;
1463
+
1464
+ let i;
1465
+
1466
+ /*
1467
+ * Switch this to an integer msvs seems to have probelms with this and strncpy_s
1468
+ * char typeorbit[2];
1469
+ */
1470
+ let typeorbit;
1471
+
1472
+ /*
1473
+ * Here
1474
+ * typeorbit = 1 = 'ei'
1475
+ * typeorbit = 2 = 'ce'
1476
+ * typeorbit = 3 = 'ci'
1477
+ * typeorbit = 4 = 'ee'
1478
+ */
1479
+
1480
+ const halfpi = 0.5 * PI;
1481
+ const small = 0.00000001;
1482
+ const unknown = 999999.1; /** Ootk -- original undefined is illegal in JS */
1483
+ const infinite = 999999.9;
1484
+
1485
+ // ------------------------- implementation -----------------
1486
+ const magr = Sgp4.mag_(r);
1487
+ const magv = Sgp4.mag_(v);
1488
+
1489
+ // ------------------ find h n and e vectors ----------------
1490
+ const hbar = Sgp4.cross_(r, v);
1491
+ const magh = Sgp4.mag_(hbar);
1492
+
1493
+ if (magh > small) {
1494
+ nbar[0] = -hbar[1];
1495
+ nbar[1] = hbar[0];
1496
+ nbar[2] = 0.0;
1497
+ magn = Sgp4.mag_(nbar);
1498
+ const c1 = magv * magv - mus / magr;
1499
+
1500
+ rdotv = Sgp4.dot_(r, v);
1501
+ for (i = 0; i <= 2; i++) {
1502
+ ebar[i] = (c1 * (r[i] as number) - rdotv * (v[i] as number)) / mus;
1503
+ }
1504
+ ecc = Sgp4.mag_(ebar);
1505
+
1506
+ // ------------ find a e and semi-latus rectum ----------
1507
+ sme = magv * magv * 0.5 - mus / magr;
1508
+ if (Math.abs(sme) > small) {
1509
+ a = -mus / (2.0 * sme);
1510
+ } else {
1511
+ a = infinite;
1512
+ }
1513
+ p = (magh * magh) / mus;
1514
+
1515
+ // ----------------- find inclination -------------------
1516
+ hk = hbar[2] / magh;
1517
+ incl = Math.acos(hk);
1518
+
1519
+ /*
1520
+ * -------- determine type of orbit for later use --------
1521
+ * ------ elliptical, parabolic, hyperbolic inclined -------
1522
+ */
1523
+ typeorbit = 1;
1524
+
1525
+ if (ecc < small) {
1526
+ // ---------------- circular equatorial ---------------
1527
+ if (incl < small || Math.abs(incl - PI) < small) {
1528
+ typeorbit = 2;
1529
+ } else {
1530
+ // -------------- circular inclined ---------------
1531
+ typeorbit = 3;
1532
+ }
1533
+ // - elliptical, parabolic, hyperbolic equatorial --
1534
+ } else if (incl < small || Math.abs(incl - PI) < small) {
1535
+ typeorbit = 4;
1536
+ }
1537
+
1538
+ // ---------- find right ascension of the ascending node ------------
1539
+ if (magn > small) {
1540
+ let temp = nbar[0] / magn;
1541
+
1542
+ if (Math.abs(temp) > 1.0) {
1543
+ temp = Sgp4.sgn_(temp);
1544
+ }
1545
+ omega = Math.acos(temp);
1546
+ if (nbar[1] < 0.0) {
1547
+ omega = TAU - omega;
1548
+ }
1549
+ } else {
1550
+ omega = unknown;
1551
+ }
1552
+
1553
+ // ---------------- find argument of perigee ---------------
1554
+ if (typeorbit === 1) {
1555
+ argp = Sgp4.angle_(nbar, ebar);
1556
+ if (ebar[2] < 0.0) {
1557
+ argp = TAU - argp;
1558
+ }
1559
+ } else {
1560
+ argp = unknown;
1561
+ }
1562
+
1563
+ // ------------ find true anomaly at epoch -------------
1564
+ if (typeorbit === 1 || typeorbit === 4) {
1565
+ nu = Sgp4.angle_(ebar, r);
1566
+ if (rdotv < 0.0) {
1567
+ nu = TAU - nu;
1568
+ }
1569
+ } else {
1570
+ nu = unknown;
1571
+ }
1572
+
1573
+ // ---- find argument of latitude - circular inclined -----
1574
+ if (typeorbit === 3) {
1575
+ arglat = Sgp4.angle_(nbar, r);
1576
+ if (r[2] < 0.0) {
1577
+ arglat = TAU - arglat;
1578
+ }
1579
+ m = arglat;
1580
+ } else {
1581
+ arglat = unknown;
1582
+ }
1583
+
1584
+ if (ecc > small && typeorbit === 4) {
1585
+ let temp = ebar[0] / ecc;
1586
+
1587
+ if (Math.abs(temp) > 1.0) {
1588
+ temp = Sgp4.sgn_(temp);
1589
+ }
1590
+ lonper = Math.acos(temp);
1591
+ if (ebar[1] < 0.0) {
1592
+ lonper = TAU - lonper;
1593
+ }
1594
+ if (incl > halfpi) {
1595
+ lonper = TAU - lonper;
1596
+ }
1597
+ } else {
1598
+ lonper = unknown;
1599
+ }
1600
+
1601
+ // -------- find true longitude - circular equatorial ------
1602
+ if (magr > small && typeorbit === 2) {
1603
+ let temp = r[0] / magr;
1604
+
1605
+ if (Math.abs(temp) > 1.0) {
1606
+ temp = Sgp4.sgn_(temp);
1607
+ }
1608
+ truelon = Math.acos(temp);
1609
+ if (r[1] < 0.0) {
1610
+ truelon = TAU - truelon;
1611
+ }
1612
+ if (incl > halfpi) {
1613
+ truelon = TAU - truelon;
1614
+ }
1615
+ m = truelon;
1616
+ } else {
1617
+ truelon = unknown;
1618
+ }
1619
+
1620
+ // ------------ find mean anomaly for all orbits -----------
1621
+ if (typeorbit === 1 || typeorbit === 4) {
1622
+ m = Sgp4.newtonnu_(ecc, nu).m;
1623
+ }
1624
+ } else {
1625
+ p = unknown;
1626
+ a = unknown;
1627
+ ecc = unknown;
1628
+ incl = unknown;
1629
+ omega = unknown;
1630
+ argp = unknown;
1631
+ nu = unknown;
1632
+ m = unknown;
1633
+ arglat = unknown;
1634
+ truelon = unknown;
1635
+ lonper = unknown;
1636
+ }
1637
+
1638
+ return {
1639
+ p,
1640
+ a,
1641
+ ecc,
1642
+ incl,
1643
+ omega,
1644
+ argp,
1645
+ nu,
1646
+ m,
1647
+ arglat,
1648
+ truelon,
1649
+ lonper,
1650
+ };
1651
+ }
1652
+
1653
+ /**
1654
+ * Determines the sign of a given number.
1655
+ * @param x - The input number to evaluate.
1656
+ * @returns `-1.0` if the input number is less than `0.0`, otherwise `1.0`.
1657
+ */
1658
+ private static sgn_(x: number): number {
1659
+ if (x < 0.0) {
1660
+ return -1.0;
1661
+ }
1662
+
1663
+ return 1.0;
1664
+ }
1665
+
1666
+ /**
1667
+ * Computes the hyperbolic sine of a given number.
1668
+ *
1669
+ * The hyperbolic sine is calculated using the formula:
1670
+ * sinh(x) = (e^x - e^(-x)) / 2
1671
+ * @param x - The input number for which to calculate the hyperbolic sine.
1672
+ * @returns The hyperbolic sine of the input number.
1673
+ */
1674
+ private static sinh_(x: number): number {
1675
+ return (Math.exp(x) - Math.exp(-x)) / 2;
1676
+ }
1677
+
1678
+ /*
1679
+ * -----------------------------------------------------------------------------
1680
+ *
1681
+ * procedure dpper
1682
+ *
1683
+ * this procedure provides deep space long period periodic contributions
1684
+ * to the mean elements. by design, these periodics are zero at epoch.
1685
+ * this used to be dscom which included initialization, but it's really a
1686
+ * recurring function.
1687
+ *
1688
+ * author : david vallado 719-573-2600 28 jun 2005
1689
+ *
1690
+ * inputs :
1691
+ * e3 -
1692
+ * ee2 -
1693
+ * peo -
1694
+ * pgho -
1695
+ * pho -
1696
+ * PInco -
1697
+ * plo -
1698
+ * se2 , se3 , sgh2, sgh3, sgh4, sh2, sh3, si2, si3, sl2, sl3, sl4 -
1699
+ * t -
1700
+ * xh2, xh3, xi2, xi3, xl2, xl3, xl4 -
1701
+ * zmol -
1702
+ * zmos -
1703
+ * ep - eccentricity 0.0 - 1.0
1704
+ * inclo - inclination - needed for lyddane modification
1705
+ * nodep - right ascension of ascending node
1706
+ * argpp - argument of perigee
1707
+ * mp - mean anomaly
1708
+ *
1709
+ * outputs :
1710
+ * ep - eccentricity 0.0 - 1.0
1711
+ * inclp - inclination
1712
+ * nodep - right ascension of ascending node
1713
+ * argpp - argument of perigee
1714
+ * mp - mean anomaly
1715
+ *
1716
+ * locals :
1717
+ * alfdp -
1718
+ * betdp -
1719
+ * cosip , sinip , cosop , sinop ,
1720
+ * dalf -
1721
+ * dbet -
1722
+ * dls -
1723
+ * f2, f3 -
1724
+ * pe -
1725
+ * pgh -
1726
+ * ph -
1727
+ * PInc -
1728
+ * pl -
1729
+ * sel , ses , sghl , sghs , shl , shs , sil , sinzf , sis ,
1730
+ * sll , sls
1731
+ * xls -
1732
+ * xnoh -
1733
+ * zf -
1734
+ * zm -
1735
+ *
1736
+ * coupling :
1737
+ * none.
1738
+ *
1739
+ * references :
1740
+ * hoots, roehrich, norad spacetrack report #3 1980
1741
+ * hoots, norad spacetrack report #6 1986
1742
+ * hoots, schumacher and glover 2004
1743
+ * vallado, crawford, hujsak, kelso 2006
1744
+ * ----------------------------------------------------------------------------
1745
+ */
1746
+ private static dpper_(
1747
+ options: {
1748
+ ep: number;
1749
+ inclp: number;
1750
+ nodep: number;
1751
+ argpp: number;
1752
+ mp: number;
1753
+ opsmode: string;
1754
+ init: boolean;
1755
+ satrec: SatelliteRecord;
1756
+ },
1757
+ ): { ep: number; inclp: number; nodep: number; argpp: number; mp: number } {
1758
+ const {
1759
+ e3,
1760
+ ee2,
1761
+ peo,
1762
+ pgho,
1763
+ pho,
1764
+ PInco,
1765
+ plo,
1766
+ se2,
1767
+ se3,
1768
+ sgh2,
1769
+ sgh3,
1770
+ sgh4,
1771
+ sh2,
1772
+ sh3,
1773
+ si2,
1774
+ si3,
1775
+ sl2,
1776
+ sl3,
1777
+ sl4,
1778
+ t,
1779
+ xgh2,
1780
+ xgh3,
1781
+ xgh4,
1782
+ xh2,
1783
+ xh3,
1784
+ xi2,
1785
+ xi3,
1786
+ xl2,
1787
+ xl3,
1788
+ xl4,
1789
+ zmol,
1790
+ zmos,
1791
+ } = options.satrec;
1792
+
1793
+ let { ep, inclp, nodep, argpp, mp } = options;
1794
+ const { opsmode = Sgp4OpsMode.IMPROVED, init } = options;
1795
+
1796
+ // ---------------------- constants -----------------------------
1797
+ /** Ootk -- Some variables imported from outside the class at the top */
1798
+ const zns = 1.19459e-5;
1799
+ const zes = 0.01675;
1800
+ const znl = 1.5835218e-4;
1801
+ const zel = 0.0549;
1802
+
1803
+ // --------------- calculate time varying periodics -----------
1804
+ let zm = zmos + zns * t;
1805
+ // Be sure that the initial call has time set to zero
1806
+
1807
+ if (init) {
1808
+ zm = zmos;
1809
+ }
1810
+ let zf = zm + 2.0 * zes * Math.sin(zm);
1811
+ let sinzf = Math.sin(zf);
1812
+ let f2 = 0.5 * sinzf * sinzf - 0.25;
1813
+ let f3 = -0.5 * sinzf * Math.cos(zf);
1814
+ const ses = se2 * f2 + se3 * f3;
1815
+ const sis = si2 * f2 + si3 * f3;
1816
+ const sls = sl2 * f2 + sl3 * f3 + sl4 * sinzf;
1817
+ const sghs = sgh2 * f2 + sgh3 * f3 + sgh4 * sinzf;
1818
+ const shs = sh2 * f2 + sh3 * f3;
1819
+
1820
+ zm = zmol + znl * t;
1821
+ if (init) {
1822
+ zm = zmol;
1823
+ }
1824
+ zf = zm + 2.0 * zel * Math.sin(zm);
1825
+ sinzf = Math.sin(zf);
1826
+ f2 = 0.5 * sinzf * sinzf - 0.25;
1827
+ f3 = -0.5 * sinzf * Math.cos(zf);
1828
+ const sel = ee2 * f2 + e3 * f3;
1829
+ const sil = xi2 * f2 + xi3 * f3;
1830
+ const sll = xl2 * f2 + xl3 * f3 + xl4 * sinzf;
1831
+ const sghl = xgh2 * f2 + xgh3 * f3 + xgh4 * sinzf;
1832
+ const shll = xh2 * f2 + xh3 * f3;
1833
+ let pe = ses + sel;
1834
+ let PInc = sis + sil;
1835
+ let pl = sls + sll;
1836
+ let pgh = sghs + sghl;
1837
+ let ph = shs + shll;
1838
+
1839
+ if (!init) {
1840
+ pe -= peo;
1841
+ PInc -= PInco;
1842
+ pl -= plo;
1843
+ pgh -= pgho;
1844
+ ph -= pho;
1845
+ inclp += PInc;
1846
+ ep += pe;
1847
+ const sinip = Math.sin(inclp);
1848
+ const cosip = Math.cos(inclp);
1849
+
1850
+ /* ----------------- apply periodics directly ------------ */
1851
+ /*
1852
+ * Sgp4fix for lyddane choice
1853
+ * strn3 used original inclination - this is technically feasible
1854
+ * gsfc used perturbed inclination - also technically feasible
1855
+ * probably best to readjust the 0.2 limit value and limit discontinuity
1856
+ * 0.2 rad = 11.45916 deg
1857
+ * use next line for original strn3 approach and original inclination
1858
+ * if (inclo >= 0.2)
1859
+ * use next line for gsfc version and perturbed inclination
1860
+ */
1861
+ if (inclp >= 0.2) {
1862
+ ph /= sinip;
1863
+ pgh -= cosip * ph;
1864
+ argpp += pgh;
1865
+ nodep += ph;
1866
+ mp += pl;
1867
+ } else {
1868
+ // ---- apply periodics with lyddane modification ----
1869
+ const sinop = Math.sin(nodep);
1870
+ const cosop = Math.cos(nodep);
1871
+ let alfdp = sinip * sinop;
1872
+ let betdp = sinip * cosop;
1873
+ const dalf = ph * cosop + PInc * cosip * sinop;
1874
+ const dbet = -ph * sinop + PInc * cosip * cosop;
1875
+
1876
+ alfdp += dalf;
1877
+ betdp += dbet;
1878
+ nodep %= TAU;
1879
+
1880
+ /*
1881
+ * Sgp4fix for afspc written intrinsic functions
1882
+ * nodep used without a trigonometric function ahead
1883
+ */
1884
+ /* istanbul ignore next */
1885
+ if (nodep < 0.0 && opsmode === 'a') {
1886
+ nodep += TAU;
1887
+ }
1888
+ let xls = mp + argpp + cosip * nodep;
1889
+ const dls = pl + pgh - PInc * nodep * sinip;
1890
+
1891
+ xls += dls;
1892
+ const xnoh = nodep;
1893
+
1894
+ nodep = Math.atan2(alfdp, betdp);
1895
+
1896
+ /*
1897
+ * Sgp4fix for afspc written intrinsic functions
1898
+ * nodep used without a trigonometric function ahead
1899
+ */
1900
+ /* istanbul ignore next */
1901
+ if (nodep < 0.0 && opsmode === 'a') {
1902
+ nodep += TAU;
1903
+ }
1904
+ if (Math.abs(xnoh - nodep) > PI) {
1905
+ /* istanbul ignore next */
1906
+ if (nodep < xnoh) {
1907
+ nodep += TAU;
1908
+ } else {
1909
+ nodep -= TAU;
1910
+ }
1911
+ }
1912
+ mp += pl;
1913
+ argpp = xls - mp - cosip * nodep;
1914
+ }
1915
+ } // If !init
1916
+
1917
+ return {
1918
+ ep,
1919
+ inclp,
1920
+ nodep,
1921
+ argpp,
1922
+ mp,
1923
+ };
1924
+ }
1925
+
1926
+ /*
1927
+ *-----------------------------------------------------------------------------
1928
+ *
1929
+ * procedure dscom
1930
+ *
1931
+ * this procedure provides deep space common items used by both the secular
1932
+ * and periodics subroutines. input is provided as shown. this routine
1933
+ * used to be called dpper, but the functions inside weren't well organized.
1934
+ *
1935
+ * author : david vallado 719-573-2600 28 jun 2005
1936
+ *
1937
+ * inputs :
1938
+ * epoch -
1939
+ * ep - eccentricity
1940
+ * argpp - argument of perigee
1941
+ * tc -
1942
+ * inclp - inclination
1943
+ * nodep - right ascension of ascending node
1944
+ * np - mean motion
1945
+ *
1946
+ * outputs :
1947
+ * sinim , cosim , sinomm , cosomm , snodm , cnodm
1948
+ * day -
1949
+ * e3 -
1950
+ * ee2 -
1951
+ * em - eccentricity
1952
+ * emsq - eccentricity squared
1953
+ * gam -
1954
+ * peo -
1955
+ * pgho -
1956
+ * pho -
1957
+ * PInco -
1958
+ * plo -
1959
+ * rtemsq -
1960
+ * se2, se3 -
1961
+ * sgh2, sgh3, sgh4 -
1962
+ * sh2, sh3, si2, si3, sl2, sl3, sl4 -
1963
+ * s1, s2, s3, s4, s5, s6, s7 -
1964
+ * ss1, ss2, ss3, ss4, ss5, ss6, ss7, sz1, sz2, sz3 -
1965
+ * sz11, sz12, sz13, sz21, sz22, sz23, sz31, sz32, sz33 -
1966
+ * xgh2, xgh3, xgh4, xh2, xh3, xi2, xi3, xl2, xl3, xl4 -
1967
+ * nm - mean motion
1968
+ * z1, z2, z3, z11, z12, z13, z21, z22, z23, z31, z32, z33 -
1969
+ * zmol -
1970
+ * zmos -
1971
+ *
1972
+ * locals :
1973
+ * a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 -
1974
+ * betasq -
1975
+ * cc -
1976
+ * ctem, stem -
1977
+ * x1, x2, x3, x4, x5, x6, x7, x8 -
1978
+ * xnodce -
1979
+ * xnoi -
1980
+ * zcosg , zsing , zcosgl , zsingl , zcosh , zsinh , zcoshl , zsinhl ,
1981
+ * zcosi , zsini , zcosil , zsinil ,
1982
+ * zx -
1983
+ * zy -
1984
+ *
1985
+ * coupling :
1986
+ * none.
1987
+ *
1988
+ * references :
1989
+ * hoots, roehrich, norad spacetrack report #3 1980
1990
+ * hoots, norad spacetrack report #6 1986
1991
+ * hoots, schumacher and glover 2004
1992
+ * vallado, crawford, hujsak, kelso 2006
1993
+ *----------------------------------------------------------------------------
1994
+ */
1995
+ private static dscom_(options: {
1996
+ epoch: number;
1997
+ ep: number;
1998
+ argpp: number;
1999
+ tc: number;
2000
+ inclp: number;
2001
+ nodep: number;
2002
+ np: number;
2003
+ }): {
2004
+ snodm: number;
2005
+ cnodm: number;
2006
+ sinim: number;
2007
+ cosim: number;
2008
+ sinomm: number;
2009
+ cosomm: number;
2010
+ day: number;
2011
+ e3: number;
2012
+ ee2: number;
2013
+ em: number;
2014
+ emsq: number;
2015
+ gam: number;
2016
+ peo: number;
2017
+ pgho: number;
2018
+ pho: number;
2019
+ PInco: number;
2020
+ plo: number;
2021
+ rtemsq: number;
2022
+ se2: number;
2023
+ se3: number;
2024
+ sgh2: number;
2025
+ sgh3: number;
2026
+ sgh4: number;
2027
+ sh2: number;
2028
+ sh3: number;
2029
+ si2: number;
2030
+ si3: number;
2031
+ sl2: number;
2032
+ sl3: number;
2033
+ sl4: number;
2034
+ s1?: number;
2035
+ s2?: number;
2036
+ s3?: number;
2037
+ s4?: number;
2038
+ s5?: number;
2039
+ s6?: number;
2040
+ s7?: number;
2041
+ ss1?: number;
2042
+ ss2?: number;
2043
+ ss3?: number;
2044
+ ss4?: number;
2045
+ ss5?: number;
2046
+ ss6?: number;
2047
+ ss7?: number;
2048
+ sz1?: number;
2049
+ sz2?: number;
2050
+ sz3?: number;
2051
+ sz11?: number;
2052
+ sz12?: number;
2053
+ sz13?: number;
2054
+ sz21?: number;
2055
+ sz22?: number;
2056
+ sz23?: number;
2057
+ sz31?: number;
2058
+ sz32?: number;
2059
+ sz33?: number;
2060
+ xgh2: number;
2061
+ xgh3: number;
2062
+ xgh4: number;
2063
+ xh2: number;
2064
+ xh3: number;
2065
+ xi2: number;
2066
+ xi3: number;
2067
+ xl2: number;
2068
+ xl3: number;
2069
+ xl4: number;
2070
+ nm: number;
2071
+ z1?: number;
2072
+ z2?: number;
2073
+ z3?: number;
2074
+ z11?: number;
2075
+ z12?: number;
2076
+ z13?: number;
2077
+ z21?: number;
2078
+ z22?: number;
2079
+ z23?: number;
2080
+ z31?: number;
2081
+ z32?: number;
2082
+ z33?: number;
2083
+ zmol: number;
2084
+ zmos: number;
2085
+ } {
2086
+ const { epoch, ep, argpp, tc, inclp, nodep, np } = options;
2087
+
2088
+ // -------------------------- constants -------------------------
2089
+ /** Ootk -- Some variables imported from outside the class at the top */
2090
+ const zes = 0.01675;
2091
+ const zel = 0.0549;
2092
+ const c1ss = 2.9864797e-6;
2093
+ const c1l = 4.7968065e-7;
2094
+ const zsinis = 0.39785416;
2095
+ const zcosis = 0.91744867;
2096
+ const zcosgs = 0.1945905;
2097
+ const zsings = -0.98088458;
2098
+
2099
+ // --------------------- local variables ------------------------
2100
+ let s1 = 0,
2101
+ s2 = 0,
2102
+ s3 = 0,
2103
+ s4 = 0,
2104
+ s5 = 0,
2105
+ s6 = 0,
2106
+ s7 = 0,
2107
+ ss1 = 0,
2108
+ ss2 = 0,
2109
+ ss3 = 0,
2110
+ ss4 = 0,
2111
+ ss5 = 0,
2112
+ ss6 = 0,
2113
+ ss7 = 0,
2114
+ sz1 = 0,
2115
+ sz11 = 0,
2116
+ sz12 = 0,
2117
+ sz13 = 0,
2118
+ sz2 = 0,
2119
+ sz21 = 0,
2120
+ sz22 = 0,
2121
+ sz23 = 0,
2122
+ sz3 = 0,
2123
+ sz31 = 0,
2124
+ sz32 = 0,
2125
+ sz33 = 0,
2126
+ z1 = 0,
2127
+ z11 = 0,
2128
+ z12 = 0,
2129
+ z13 = 0,
2130
+ z2 = 0,
2131
+ z21 = 0,
2132
+ z22 = 0,
2133
+ z23 = 0,
2134
+ z3 = 0,
2135
+ z31 = 0,
2136
+ z32 = 0,
2137
+ z33 = 0;
2138
+ const nm = np;
2139
+ const em = ep;
2140
+ const snodm = Math.sin(nodep);
2141
+ const cnodm = Math.cos(nodep);
2142
+ const sinomm = Math.sin(argpp);
2143
+ const cosomm = Math.cos(argpp);
2144
+ const sinim = Math.sin(inclp);
2145
+ const cosim = Math.cos(inclp);
2146
+ const emsq = em * em;
2147
+ const betasq = 1.0 - emsq;
2148
+ const rtemsq = Math.sqrt(betasq);
2149
+
2150
+ // ----------------- initialize lunar solar terms ---------------
2151
+ const peo = 0.0;
2152
+ const PInco = 0.0;
2153
+ const plo = 0.0;
2154
+ const pgho = 0.0;
2155
+ const pho = 0.0;
2156
+ const day = epoch + 18261.5 + tc / 1440.0;
2157
+ const xnodce = (4.523602 - 9.2422029e-4 * day) % TAU;
2158
+ const stem = Math.sin(xnodce);
2159
+ const ctem = Math.cos(xnodce);
2160
+ const zcosil = 0.91375164 - 0.03568096 * ctem;
2161
+ const zsinil = Math.sqrt(1.0 - zcosil * zcosil);
2162
+ const zsinhl = (0.089683511 * stem) / zsinil;
2163
+ const zcoshl = Math.sqrt(1.0 - zsinhl * zsinhl);
2164
+ const gam = 5.8351514 + 0.001944368 * day;
2165
+ let zx = (0.39785416 * stem) / zsinil;
2166
+ const zy = zcoshl * ctem + 0.91744867 * zsinhl * stem;
2167
+
2168
+ zx = Math.atan2(zx, zy);
2169
+ zx += gam - xnodce;
2170
+ const zcosgl = Math.cos(zx);
2171
+ const zsingl = Math.sin(zx);
2172
+
2173
+ // ------------------------- do solar terms ---------------------
2174
+ let zcosg = zcosgs;
2175
+ let zsing = zsings;
2176
+ let zcosi = zcosis;
2177
+ let zsini = zsinis;
2178
+ let zcosh = cnodm;
2179
+ let zsinh = snodm;
2180
+ let cc = c1ss;
2181
+ const xnoi = 1.0 / nm;
2182
+
2183
+ for (let lsflg = 1; lsflg <= 2; lsflg++) {
2184
+ const a1 = zcosg * zcosh + zsing * zcosi * zsinh;
2185
+ const a3 = -zsing * zcosh + zcosg * zcosi * zsinh;
2186
+ const a7 = -zcosg * zsinh + zsing * zcosi * zcosh;
2187
+ const a8 = zsing * zsini;
2188
+ const a9 = zsing * zsinh + zcosg * zcosi * zcosh;
2189
+ const a10 = zcosg * zsini;
2190
+ const a2 = cosim * a7 + sinim * a8;
2191
+ const a4 = cosim * a9 + sinim * a10;
2192
+ const a5 = -sinim * a7 + cosim * a8;
2193
+ const a6 = -sinim * a9 + cosim * a10;
2194
+
2195
+ const x1 = a1 * cosomm + a2 * sinomm;
2196
+ const x2 = a3 * cosomm + a4 * sinomm;
2197
+ const x3 = -a1 * sinomm + a2 * cosomm;
2198
+ const x4 = -a3 * sinomm + a4 * cosomm;
2199
+ const x5 = a5 * sinomm;
2200
+ const x6 = a6 * sinomm;
2201
+ const x7 = a5 * cosomm;
2202
+ const x8 = a6 * cosomm;
2203
+
2204
+ z31 = 12.0 * x1 * x1 - 3.0 * x3 * x3;
2205
+ z32 = 24.0 * x1 * x2 - 6.0 * x3 * x4;
2206
+ z33 = 12.0 * x2 * x2 - 3.0 * x4 * x4;
2207
+
2208
+ z1 = 3.0 * (a1 * a1 + a2 * a2) + z31 * emsq;
2209
+ z2 = 6.0 * (a1 * a3 + a2 * a4) + z32 * emsq;
2210
+ z3 = 3.0 * (a3 * a3 + a4 * a4) + z33 * emsq;
2211
+
2212
+ z11 = -6.0 * a1 * a5 + emsq * (-24.0 * x1 * x7 - 6.0 * x3 * x5);
2213
+ z12 = -6.0 * (a1 * a6 + a3 * a5) + emsq * (-24.0 * (x2 * x7 + x1 * x8) + -6.0 * (x3 * x6 + x4 * x5));
2214
+
2215
+ z13 = -6.0 * a3 * a6 + emsq * (-24.0 * x2 * x8 - 6.0 * x4 * x6);
2216
+
2217
+ z21 = 6.0 * a2 * a5 + emsq * (24.0 * x1 * x5 - 6.0 * x3 * x7);
2218
+ z22 = 6.0 * (a4 * a5 + a2 * a6) + emsq * (24.0 * (x2 * x5 + x1 * x6) - 6.0 * (x4 * x7 + x3 * x8));
2219
+ z23 = 6.0 * a4 * a6 + emsq * (24.0 * x2 * x6 - 6.0 * x4 * x8);
2220
+
2221
+ z1 = z1 + z1 + betasq * z31;
2222
+ z2 = z2 + z2 + betasq * z32;
2223
+ z3 = z3 + z3 + betasq * z33;
2224
+ s3 = cc * xnoi;
2225
+ s2 = (-0.5 * s3) / rtemsq;
2226
+ s4 = s3 * rtemsq;
2227
+ s1 = -15.0 * em * s4;
2228
+ s5 = x1 * x3 + x2 * x4;
2229
+ s6 = x2 * x3 + x1 * x4;
2230
+ s7 = x2 * x4 - x1 * x3;
2231
+
2232
+ // ----------------------- do lunar terms -------------------
2233
+ if (lsflg === 1) {
2234
+ ss1 = s1;
2235
+ ss2 = s2;
2236
+ ss3 = s3;
2237
+ ss4 = s4;
2238
+ ss5 = s5;
2239
+ ss6 = s6;
2240
+ ss7 = s7;
2241
+ sz1 = z1;
2242
+ sz2 = z2;
2243
+ sz3 = z3;
2244
+ sz11 = z11;
2245
+ sz12 = z12;
2246
+ sz13 = z13;
2247
+ sz21 = z21;
2248
+ sz22 = z22;
2249
+ sz23 = z23;
2250
+ sz31 = z31;
2251
+ sz32 = z32;
2252
+ sz33 = z33;
2253
+ zcosg = zcosgl;
2254
+ zsing = zsingl;
2255
+ zcosi = zcosil;
2256
+ zsini = zsinil;
2257
+ zcosh = zcoshl * cnodm + zsinhl * snodm;
2258
+ zsinh = snodm * zcoshl - cnodm * zsinhl;
2259
+ cc = c1l;
2260
+ }
2261
+ }
2262
+
2263
+ const zmol = (4.7199672 + (0.2299715 * day - gam)) % TAU;
2264
+ const zmos = (6.2565837 + 0.017201977 * day) % TAU;
2265
+
2266
+ // ------------------------ do solar terms ----------------------
2267
+ const se2 = 2.0 * ss1 * ss6;
2268
+ const se3 = 2.0 * ss1 * ss7;
2269
+ const si2 = 2.0 * ss2 * sz12;
2270
+ const si3 = 2.0 * ss2 * (sz13 - sz11);
2271
+ const sl2 = -2.0 * ss3 * sz2;
2272
+ const sl3 = -2.0 * ss3 * (sz3 - sz1);
2273
+ const sl4 = -2.0 * ss3 * (-21.0 - 9.0 * emsq) * zes;
2274
+ const sgh2 = 2.0 * ss4 * sz32;
2275
+ const sgh3 = 2.0 * ss4 * (sz33 - sz31);
2276
+ const sgh4 = -18.0 * ss4 * zes;
2277
+ const sh2 = -2.0 * ss2 * sz22;
2278
+ const sh3 = -2.0 * ss2 * (sz23 - sz21);
2279
+
2280
+ // ------------------------ do lunar terms ----------------------
2281
+ const ee2 = 2.0 * s1 * s6;
2282
+ const e3 = 2.0 * s1 * s7;
2283
+ const xi2 = 2.0 * s2 * z12;
2284
+ const xi3 = 2.0 * s2 * (z13 - z11);
2285
+ const xl2 = -2.0 * s3 * z2;
2286
+ const xl3 = -2.0 * s3 * (z3 - z1);
2287
+ const xl4 = -2.0 * s3 * (-21.0 - 9.0 * emsq) * zel;
2288
+ const xgh2 = 2.0 * s4 * z32;
2289
+ const xgh3 = 2.0 * s4 * (z33 - z31);
2290
+ const xgh4 = -18.0 * s4 * zel;
2291
+ const xh2 = -2.0 * s2 * z22;
2292
+ const xh3 = -2.0 * s2 * (z23 - z21);
2293
+
2294
+ return {
2295
+ snodm,
2296
+ cnodm,
2297
+ sinim,
2298
+ cosim,
2299
+ sinomm,
2300
+ cosomm,
2301
+ day,
2302
+ e3,
2303
+ ee2,
2304
+ em,
2305
+ emsq,
2306
+ gam,
2307
+ peo,
2308
+ pgho,
2309
+ pho,
2310
+ PInco,
2311
+ plo,
2312
+ rtemsq,
2313
+ se2,
2314
+ se3,
2315
+ sgh2,
2316
+ sgh3,
2317
+ sgh4,
2318
+ sh2,
2319
+ sh3,
2320
+ si2,
2321
+ si3,
2322
+ sl2,
2323
+ sl3,
2324
+ sl4,
2325
+ s1,
2326
+ s2,
2327
+ s3,
2328
+ s4,
2329
+ s5,
2330
+ s6,
2331
+ s7,
2332
+ ss1,
2333
+ ss2,
2334
+ ss3,
2335
+ ss4,
2336
+ ss5,
2337
+ ss6,
2338
+ ss7,
2339
+ sz1,
2340
+ sz2,
2341
+ sz3,
2342
+ sz11,
2343
+ sz12,
2344
+ sz13,
2345
+ sz21,
2346
+ sz22,
2347
+ sz23,
2348
+ sz31,
2349
+ sz32,
2350
+ sz33,
2351
+ xgh2,
2352
+ xgh3,
2353
+ xgh4,
2354
+ xh2,
2355
+ xh3,
2356
+ xi2,
2357
+ xi3,
2358
+ xl2,
2359
+ xl3,
2360
+ xl4,
2361
+ nm,
2362
+ z1,
2363
+ z2,
2364
+ z3,
2365
+ z11,
2366
+ z12,
2367
+ z13,
2368
+ z21,
2369
+ z22,
2370
+ z23,
2371
+ z31,
2372
+ z32,
2373
+ z33,
2374
+ zmol,
2375
+ zmos,
2376
+ };
2377
+ }
2378
+
2379
+ /*
2380
+ *-----------------------------------------------------------------------------
2381
+ *
2382
+ * procedure dsinit
2383
+ *
2384
+ * this procedure provides deep space contributions to mean motion dot due
2385
+ * to geopotential resonance with half day and one day orbits.
2386
+ *
2387
+ * author : david vallado 719-573-2600 28 jun 2005
2388
+ *
2389
+ * inputs :
2390
+ * cosim, sinim-
2391
+ * emsq - eccentricity squared
2392
+ * argpo - argument of perigee
2393
+ * s1, s2, s3, s4, s5 -
2394
+ * ss1, ss2, ss3, ss4, ss5 -
2395
+ * sz1, sz3, sz11, sz13, sz21, sz23, sz31, sz33 -
2396
+ * t - time
2397
+ * tc -
2398
+ * gsto - greenwich sidereal time rad
2399
+ * mo - mean anomaly
2400
+ * mdot - mean anomaly dot (rate)
2401
+ * no - mean motion
2402
+ * nodeo - right ascension of ascending node
2403
+ * nodedot - right ascension of ascending node dot (rate)
2404
+ * xPIdot -
2405
+ * z1, z3, z11, z13, z21, z23, z31, z33 -
2406
+ * eccm - eccentricity
2407
+ * argpm - argument of perigee
2408
+ * inclm - inclination
2409
+ * mm - mean anomaly
2410
+ * xn - mean motion
2411
+ * nodem - right ascension of ascending node
2412
+ *
2413
+ * outputs :
2414
+ * em - eccentricity
2415
+ * argpm - argument of perigee
2416
+ * inclm - inclination
2417
+ * mm - mean anomaly
2418
+ * nm - mean motion
2419
+ * nodem - right ascension of ascending node
2420
+ * irez - flag for resonance 0-none, 1-one day, 2-half day
2421
+ * atime -
2422
+ * d2201, d2211, d3210, d3222, d4410, d4422, d5220, d5232, d5421, d5433 -
2423
+ * dedt -
2424
+ * didt -
2425
+ * dmdt -
2426
+ * dndt -
2427
+ * dnodt -
2428
+ * domdt -
2429
+ * del1, del2, del3 -
2430
+ * ses , sghl , sghs , sgs , shl , shs , sis , sls
2431
+ * theta -
2432
+ * xfact -
2433
+ * xlamo -
2434
+ * xli -
2435
+ * xni
2436
+ *
2437
+ * locals :
2438
+ * ainv2 -
2439
+ * aonv -
2440
+ * cosisq -
2441
+ * eoc -
2442
+ * f220, f221, f311, f321, f322, f330, f441, f442, f522, f523, f542, f543 -
2443
+ * g200, g201, g211, g300, g310, g322, g410, g422, g520, g521, g532, g533 -
2444
+ * sini2 -
2445
+ * temp -
2446
+ * temp1 -
2447
+ * theta -
2448
+ * xno2 -
2449
+ *
2450
+ * coupling :
2451
+ * getgravconst
2452
+ *
2453
+ * references :
2454
+ * hoots, roehrich, norad spacetrack report #3 1980
2455
+ * hoots, norad spacetrack report #6 1986
2456
+ * hoots, schumacher and glover 2004
2457
+ * vallado, crawford, hujsak, kelso 2006
2458
+ *----------------------------------------------------------------------------
2459
+ */
2460
+ private static dsinit_(options: DsInitParams): {
2461
+ em: number;
2462
+ argpm: number;
2463
+ inclm: number;
2464
+ mm: number;
2465
+ nm: number;
2466
+ nodem: number;
2467
+ irez: number;
2468
+ atime: number;
2469
+ d2201: number;
2470
+ d2211: number;
2471
+ d3210: number;
2472
+ d3222: number;
2473
+ d4410: number;
2474
+ d4422: number;
2475
+ d5220: number;
2476
+ d5232: number;
2477
+ d5421: number;
2478
+ d5433: number;
2479
+ dedt: number;
2480
+ didt: number;
2481
+ dmdt: number;
2482
+ dndt: number;
2483
+ dnodt: number;
2484
+ domdt: number;
2485
+ del1: number;
2486
+ del2: number;
2487
+ del3: number;
2488
+ xfact: number;
2489
+ xlamo: number;
2490
+ xli: number;
2491
+ xni: number;
2492
+ } {
2493
+ /*
2494
+ * Sgp4fix just send in xke as a constant and eliminate getgravconst call
2495
+ * gravconsttype whichconst,
2496
+ */
2497
+ const {
2498
+ xke,
2499
+ cosim,
2500
+ argpo,
2501
+ s1,
2502
+ s2,
2503
+ s3,
2504
+ s4,
2505
+ s5,
2506
+ sinim,
2507
+ ss1,
2508
+ ss2,
2509
+ ss3,
2510
+ ss4,
2511
+ ss5,
2512
+ sz1,
2513
+ sz3,
2514
+ sz11,
2515
+ sz13,
2516
+ sz21,
2517
+ sz23,
2518
+ sz31,
2519
+ sz33,
2520
+ t,
2521
+ tc,
2522
+ gsto,
2523
+ mo,
2524
+ mdot,
2525
+ no,
2526
+ nodeo,
2527
+ nodedot,
2528
+ xPIdot,
2529
+ z1,
2530
+ z3,
2531
+ z11,
2532
+ z13,
2533
+ z21,
2534
+ z23,
2535
+ z31,
2536
+ z33,
2537
+ ecco,
2538
+ eccsq,
2539
+ } = options;
2540
+
2541
+ let {
2542
+ emsq,
2543
+ em,
2544
+ argpm,
2545
+ inclm,
2546
+ mm,
2547
+ nm,
2548
+ nodem,
2549
+ atime,
2550
+ d2201,
2551
+ d2211,
2552
+ d3210,
2553
+ d3222,
2554
+ d4410,
2555
+ d4422,
2556
+ d5220,
2557
+ d5232,
2558
+ d5421,
2559
+ d5433,
2560
+ del1,
2561
+ del2,
2562
+ del3,
2563
+ xfact,
2564
+ xlamo,
2565
+ xli,
2566
+ xni,
2567
+ } = options;
2568
+
2569
+ /* --------------------- local variables ------------------------ */
2570
+ /** Ootk -- Some variables imported from outside the class at the top */
2571
+ const q22 = 1.7891679e-6;
2572
+ const q31 = 2.1460748e-6;
2573
+ const q33 = 2.2123015e-7;
2574
+ const root22 = 1.7891679e-6;
2575
+ const root44 = 7.3636953e-9;
2576
+ const root54 = 2.1765803e-9;
2577
+ const rptim = 4.37526908801129966e-3; // Equates to 7.29211514668855e-5 rad/sec
2578
+ const root32 = 3.7393792e-7;
2579
+ const root52 = 1.1428639e-7;
2580
+ const x2o3 = 2.0 / 3.0;
2581
+ const znl = 1.5835218e-4;
2582
+ const zns = 1.19459e-5;
2583
+
2584
+ /*
2585
+ * Sgp4fix identify constants and allow alternate values
2586
+ * just xke is used here so pass it in rather than have multiple calls
2587
+ * getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
2588
+ */
2589
+
2590
+ // -------------------- deep space initialization ------------
2591
+ let irez = 0;
2592
+
2593
+ if (nm < 0.0052359877 && nm > 0.0034906585) {
2594
+ irez = 1;
2595
+ }
2596
+ if (nm >= 8.26e-3 && nm <= 9.24e-3 && em >= 0.5) {
2597
+ irez = 2;
2598
+ }
2599
+
2600
+ // ------------------------ do solar terms -------------------
2601
+ const ses = ss1 * zns * ss5;
2602
+ const sis = ss2 * zns * (sz11 + sz13);
2603
+ const sls = -zns * ss3 * (sz1 + sz3 - 14.0 - 6.0 * emsq);
2604
+ const sghs = ss4 * zns * (sz31 + sz33 - 6.0);
2605
+ let shs = -zns * ss2 * (sz21 + sz23);
2606
+
2607
+ // Sgp4fix for 180 deg incl
2608
+ if (inclm < 5.2359877e-2 || inclm > PI - 5.2359877e-2) {
2609
+ shs = 0.0;
2610
+ }
2611
+ if (sinim !== 0.0) {
2612
+ shs /= sinim;
2613
+ }
2614
+ const sgs = sghs - cosim * shs;
2615
+
2616
+ // ------------------------- do lunar terms ------------------
2617
+ const dedt = ses + s1 * znl * s5;
2618
+ const didt = sis + s2 * znl * (z11 + z13);
2619
+ const dmdt = sls - znl * s3 * (z1 + z3 - 14.0 - 6.0 * emsq);
2620
+ const sghl = s4 * znl * (z31 + z33 - 6.0);
2621
+ let shll = -znl * s2 * (z21 + z23);
2622
+
2623
+ // Sgp4fix for 180 deg incl
2624
+ if (inclm < 5.2359877e-2 || inclm > PI - 5.2359877e-2) {
2625
+ shll = 0.0;
2626
+ }
2627
+ let domdt = sgs + sghl;
2628
+ let dnodt = shs;
2629
+
2630
+ if (sinim !== 0.0) {
2631
+ domdt -= (cosim / sinim) * shll;
2632
+ dnodt += shll / sinim;
2633
+ }
2634
+
2635
+ // ----------- calculate deep space resonance effects --------
2636
+ const dndt = 0.0;
2637
+ const theta = (gsto + tc * rptim) % TAU;
2638
+
2639
+ em += dedt * t;
2640
+ inclm += didt * t;
2641
+ argpm += domdt * t;
2642
+ nodem += dnodt * t;
2643
+ mm += dmdt * t;
2644
+
2645
+ /*
2646
+ * Sgp4fix for negative inclinations
2647
+ * the following if statement should be commented out
2648
+ * if (inclm < 0.0)
2649
+ * {
2650
+ * inclm = -inclm;
2651
+ * argpm = argpm - PI;
2652
+ * nodem = nodem + PI;
2653
+ * }
2654
+ */
2655
+
2656
+ // -------------- initialize the resonance terms -------------
2657
+ if (irez !== 0) {
2658
+ const aonv = (nm / xke) ** x2o3;
2659
+
2660
+ // ---------- geopotential resonance for 12 hour orbits ------
2661
+ if (irez === 2) {
2662
+ const cosisq = cosim * cosim;
2663
+ const emo = em;
2664
+
2665
+ em = ecco;
2666
+ const emsqo = emsq;
2667
+
2668
+ emsq = eccsq;
2669
+ const eoc = em * emsq;
2670
+ const g201 = -0.306 - (em - 0.64) * 0.44;
2671
+
2672
+ let g211, g310, g322, g410, g422, g520, g521, g532, g533;
2673
+
2674
+ if (em <= 0.65) {
2675
+ g211 = 3.616 - 13.247 * em + 16.29 * emsq;
2676
+ g310 = -19.302 + 117.39 * em - 228.419 * emsq + 156.591 * eoc;
2677
+ g322 = -18.9068 + 109.7927 * em - 214.6334 * emsq + 146.5816 * eoc;
2678
+ g410 = -41.122 + 242.694 * em - 471.094 * emsq + 313.953 * eoc;
2679
+ g422 = -146.407 + 841.88 * em - 1629.014 * emsq + 1083.435 * eoc;
2680
+ g520 = -532.114 + 3017.977 * em - 5740.032 * emsq + 3708.276 * eoc;
2681
+ } else {
2682
+ g211 = -72.099 + 331.819 * em - 508.738 * emsq + 266.724 * eoc;
2683
+ g310 = -346.844 + 1582.851 * em - 2415.925 * emsq + 1246.113 * eoc;
2684
+ g322 = -342.585 + 1554.908 * em - 2366.899 * emsq + 1215.972 * eoc;
2685
+ g410 = -1052.797 + 4758.686 * em - 7193.992 * emsq + 3651.957 * eoc;
2686
+ g422 = -3581.69 + 16178.11 * em - 24462.77 * emsq + 12422.52 * eoc;
2687
+ if (em > 0.715) {
2688
+ g520 = -5149.66 + 29936.92 * em - 54087.36 * emsq + 31324.56 * eoc;
2689
+ } else {
2690
+ g520 = 1464.74 - 4664.75 * em + 3763.64 * emsq;
2691
+ }
2692
+ }
2693
+ if (em < 0.7) {
2694
+ g533 = -919.2277 + 4988.61 * em - 9064.77 * emsq + 5542.21 * eoc;
2695
+ g521 = -822.71072 + 4568.6173 * em - 8491.4146 * emsq + 5337.524 * eoc;
2696
+ g532 = -853.666 + 4690.25 * em - 8624.77 * emsq + 5341.4 * eoc;
2697
+ } else {
2698
+ g533 = -37995.78 + 161616.52 * em - 229838.2 * emsq + 109377.94 * eoc;
2699
+ g521 = -51752.104 + 218913.95 * em - 309468.16 * emsq + 146349.42 * eoc;
2700
+ g532 = -40023.88 + 170470.89 * em - 242699.48 * emsq + 115605.82 * eoc;
2701
+ }
2702
+ const sini2 = sinim * sinim;
2703
+ const f220 = 0.75 * (1.0 + 2.0 * cosim + cosisq);
2704
+ const f221 = 1.5 * sini2;
2705
+ const f321 = 1.875 * sinim * (1.0 - 2.0 * cosim - 3.0 * cosisq);
2706
+ const f322 = -1.875 * sinim * (1.0 + 2.0 * cosim - 3.0 * cosisq);
2707
+ const f441 = 35.0 * sini2 * f220;
2708
+ const f442 = 39.375 * sini2 * sini2;
2709
+
2710
+ const f522 =
2711
+ 9.84375 *
2712
+ sinim *
2713
+ (sini2 * (1.0 - 2.0 * cosim - 5.0 * cosisq) + 0.33333333 * (-2.0 + 4.0 * cosim + 6.0 * cosisq));
2714
+ const f523 =
2715
+ sinim *
2716
+ (4.92187512 * sini2 * (-2.0 - 4.0 * cosim + 10.0 * cosisq) + 6.56250012 * (1.0 + 2.0 * cosim - 3.0 * cosisq));
2717
+ const f542 = 29.53125 * sinim * (2.0 - 8.0 * cosim + cosisq * (-12.0 + 8.0 * cosim + 10.0 * cosisq));
2718
+ const f543 = 29.53125 * sinim * (-2.0 - 8.0 * cosim + cosisq * (12.0 + 8.0 * cosim - 10.0 * cosisq));
2719
+
2720
+ const xno2 = nm * nm;
2721
+ const ainv2 = aonv * aonv;
2722
+ let temp1 = 3.0 * xno2 * ainv2;
2723
+ let temp = temp1 * root22;
2724
+
2725
+ d2201 = temp * f220 * g201;
2726
+ d2211 = temp * f221 * g211;
2727
+ temp1 *= aonv;
2728
+ temp = temp1 * root32;
2729
+ d3210 = temp * f321 * g310;
2730
+ d3222 = temp * f322 * g322;
2731
+ temp1 *= aonv;
2732
+ temp = 2.0 * temp1 * root44;
2733
+ d4410 = temp * f441 * g410;
2734
+ d4422 = temp * f442 * g422;
2735
+ temp1 *= aonv;
2736
+ temp = temp1 * root52;
2737
+ d5220 = temp * f522 * g520;
2738
+ d5232 = temp * f523 * g532;
2739
+ temp = 2.0 * temp1 * root54;
2740
+ d5421 = temp * f542 * g521;
2741
+ d5433 = temp * f543 * g533;
2742
+ xlamo = (mo + nodeo + nodeo - (theta + theta)) % TAU;
2743
+ xfact = mdot + dmdt + 2.0 * (nodedot + dnodt - rptim) - no;
2744
+ em = emo;
2745
+ emsq = emsqo;
2746
+ }
2747
+
2748
+ // ---------------- synchronous resonance terms --------------
2749
+ if (irez === 1) {
2750
+ const g200 = 1.0 + emsq * (-2.5 + 0.8125 * emsq);
2751
+ const g310 = 1.0 + 2.0 * emsq;
2752
+ const g300 = 1.0 + emsq * (-6.0 + 6.60937 * emsq);
2753
+ const f220 = 0.75 * (1.0 + cosim) * (1.0 + cosim);
2754
+ const f311 = 0.9375 * sinim * sinim * (1.0 + 3.0 * cosim) - 0.75 * (1.0 + cosim);
2755
+ let f330 = 1.0 + cosim;
2756
+
2757
+ f330 *= 1.875 * f330 * f330;
2758
+ del1 = 3.0 * nm * nm * aonv * aonv;
2759
+ del2 = 2.0 * del1 * f220 * g200 * q22;
2760
+ del3 = 3.0 * del1 * f330 * g300 * q33 * aonv;
2761
+ del1 = del1 * f311 * g310 * q31 * aonv;
2762
+ xlamo = (mo + nodeo + argpo - theta) % TAU;
2763
+ xfact = mdot + xPIdot + dmdt + domdt + dnodt - (no + rptim);
2764
+ }
2765
+
2766
+ // ------------ for sgp4, initialize the integrator ----------
2767
+ xli = xlamo;
2768
+ xni = no;
2769
+ atime = 0.0;
2770
+ nm = no + dndt;
2771
+ }
2772
+
2773
+ return {
2774
+ em,
2775
+ argpm,
2776
+ inclm,
2777
+ mm,
2778
+ nm,
2779
+ nodem,
2780
+ irez,
2781
+ atime,
2782
+ d2201,
2783
+ d2211,
2784
+ d3210,
2785
+ d3222,
2786
+ d4410,
2787
+ d4422,
2788
+ d5220,
2789
+ d5232,
2790
+ d5421,
2791
+ d5433,
2792
+ dedt,
2793
+ didt,
2794
+ dmdt,
2795
+ dndt,
2796
+ dnodt,
2797
+ domdt,
2798
+ del1,
2799
+ del2,
2800
+ del3,
2801
+ xfact,
2802
+ xlamo,
2803
+ xli,
2804
+ xni,
2805
+ };
2806
+ }
2807
+
2808
+ /*
2809
+ *-----------------------------------------------------------------------------
2810
+ *
2811
+ * procedure dspace
2812
+ *
2813
+ * this procedure provides deep space contributions to mean elements for
2814
+ * perturbing third body. these effects have been averaged over one
2815
+ * revolution of the sun and moon. for earth resonance effects, the
2816
+ * effects have been averaged over no revolutions of the satellite.
2817
+ * (mean motion)
2818
+ *
2819
+ * author : david vallado 719-573-2600 28 jun 2005
2820
+ *
2821
+ * inputs :
2822
+ * d2201, d2211, d3210, d3222, d4410, d4422, d5220, d5232, d5421, d5433 -
2823
+ * dedt -
2824
+ * del1, del2, del3 -
2825
+ * didt -
2826
+ * dmdt -
2827
+ * dnodt -
2828
+ * domdt -
2829
+ * irez - flag for resonance 0-none, 1-one day, 2-half day
2830
+ * argpo - argument of perigee
2831
+ * argpdot - argument of perigee dot (rate)
2832
+ * t - time
2833
+ * tc -
2834
+ * gsto - gst
2835
+ * xfact -
2836
+ * xlamo -
2837
+ * no - mean motion
2838
+ * atime -
2839
+ * em - eccentricity
2840
+ * ft -
2841
+ * argpm - argument of perigee
2842
+ * inclm - inclination
2843
+ * xli -
2844
+ * mm - mean anomaly
2845
+ * xni - mean motion
2846
+ * nodem - right ascension of ascending node
2847
+ *
2848
+ * outputs :
2849
+ * atime -
2850
+ * em - eccentricity
2851
+ * argpm - argument of perigee
2852
+ * inclm - inclination
2853
+ * xli -
2854
+ * mm - mean anomaly
2855
+ * xni -
2856
+ * nodem - right ascension of ascending node
2857
+ * dndt -
2858
+ * nm - mean motion
2859
+ *
2860
+ * locals :
2861
+ * delt -
2862
+ * ft -
2863
+ * theta -
2864
+ * x2li -
2865
+ * x2omi -
2866
+ * xl -
2867
+ * xldot -
2868
+ * xnddt -
2869
+ * xndt -
2870
+ * xomi -
2871
+ *
2872
+ * coupling :
2873
+ * none -
2874
+ *
2875
+ * references :
2876
+ * hoots, roehrich, norad spacetrack report #3 1980
2877
+ * hoots, norad spacetrack report #6 1986
2878
+ * hoots, schumacher and glover 2004
2879
+ * vallado, crawford, hujsak, kelso 2006
2880
+ *----------------------------------------------------------------------------
2881
+ */
2882
+ private static dspace_(
2883
+ em: number,
2884
+ argpm: number,
2885
+ inclm: number,
2886
+ mm: number,
2887
+ nodem: number,
2888
+ nm: number,
2889
+ satrec: SatelliteRecord,
2890
+ ): [em: number, argpm: number, inclm: number, mm: number, nodem: number, nm: number] {
2891
+
2892
+ let {
2893
+ atime,
2894
+ xli,
2895
+ xni,
2896
+ } = satrec;
2897
+ const {
2898
+ dedt,
2899
+ didt,
2900
+ dmdt,
2901
+ dnodt,
2902
+ domdt,
2903
+ irez,
2904
+ d2201,
2905
+ d2211,
2906
+ d3210,
2907
+ d3222,
2908
+ d4410,
2909
+ d4422,
2910
+ d5220,
2911
+ d5232,
2912
+ d5421,
2913
+ d5433,
2914
+ xfact,
2915
+ xlamo,
2916
+ gsto,
2917
+ argpo,
2918
+ t,
2919
+ no,
2920
+ argpdot,
2921
+ del1,
2922
+ del2,
2923
+ del3,
2924
+ } = satrec;
2925
+
2926
+ // ----------- calculate deep space resonance effects -----------
2927
+ let dndt = 0.0;
2928
+ const theta = (gsto + t * rptim) % TAU;
2929
+
2930
+ // Apply time-dependent perturbations
2931
+ em += dedt * t;
2932
+ inclm += didt * t;
2933
+ argpm += domdt * t;
2934
+ nodem += dnodt * t;
2935
+ mm += dmdt * t;
2936
+
2937
+ if (irez !== 0) {
2938
+ // Simplified deep space resonance handling
2939
+ if (atime === 0.0 || t * atime <= 0.0 || Math.abs(t) < Math.abs(atime)) {
2940
+ atime = 0.0;
2941
+ xni = no;
2942
+ xli = xlamo;
2943
+ }
2944
+
2945
+ const delt = t > 0.0 ? stepp : stepn;
2946
+
2947
+ let ft = 0;
2948
+ let x2li = 0;
2949
+ let x2omi = 0;
2950
+ let xldot = 0;
2951
+ let xnddt = 0;
2952
+ let xndt = 0;
2953
+ let xomi = 0;
2954
+ let iretn = true; // Added for do loop
2955
+
2956
+ while (iretn) {
2957
+ /*
2958
+ * ------------------- dot terms calculated -------------
2959
+ * ----------- near - synchronous resonance terms -------
2960
+ */
2961
+ if (irez !== 2) {
2962
+ xndt =
2963
+ del1 * Math.sin(xli - fasx2) + del2 * Math.sin(2.0 * (xli - fasx4)) + del3 * Math.sin(3.0 * (xli - fasx6));
2964
+ xldot = xni + xfact;
2965
+ xnddt =
2966
+ del1 * Math.cos(xli - fasx2) +
2967
+ 2.0 * del2 * Math.cos(2.0 * (xli - fasx4)) +
2968
+ 3.0 * del3 * Math.cos(3.0 * (xli - fasx6));
2969
+ xnddt *= xldot;
2970
+ } else {
2971
+ // --------- near - half-day resonance terms --------
2972
+ xomi = argpo + argpdot * atime;
2973
+ x2omi = xomi + xomi;
2974
+ x2li = xli + xli;
2975
+ xndt =
2976
+ d2201 * Math.sin(x2omi + xli - g22) +
2977
+ d2211 * Math.sin(xli - g22) +
2978
+ d3210 * Math.sin(xomi + xli - g32) +
2979
+ d3222 * Math.sin(-xomi + xli - g32) +
2980
+ d4410 * Math.sin(x2omi + x2li - g44) +
2981
+ d4422 * Math.sin(x2li - g44) +
2982
+ d5220 * Math.sin(xomi + xli - g52) +
2983
+ d5232 * Math.sin(-xomi + xli - g52) +
2984
+ d5421 * Math.sin(xomi + x2li - g54) +
2985
+ d5433 * Math.sin(-xomi + x2li - g54);
2986
+ xldot = xni + xfact;
2987
+ xnddt =
2988
+ d2201 * Math.cos(x2omi + xli - g22) +
2989
+ d2211 * Math.cos(xli - g22) +
2990
+ d3210 * Math.cos(xomi + xli - g32) +
2991
+ d3222 * Math.cos(-xomi + xli - g32) +
2992
+ d5220 * Math.cos(xomi + xli - g52) +
2993
+ d5232 * Math.cos(-xomi + xli - g52) +
2994
+ 2.0 *
2995
+ (d4410 * Math.cos(x2omi + x2li - g44) +
2996
+ d4422 * Math.cos(x2li - g44) +
2997
+ d5421 * Math.cos(xomi + x2li - g54) +
2998
+ d5433 * Math.cos(-xomi + x2li - g54));
2999
+ xnddt *= xldot;
3000
+ }
3001
+
3002
+ /*
3003
+ * ----------------------- integrator -------------------
3004
+ * sgp4fix move end checks to end of routine
3005
+ */
3006
+ if (Math.abs(t - atime) < stepp) {
3007
+ ft = t - atime;
3008
+ iretn = false;
3009
+ } else {
3010
+ xli += xldot * delt + xndt * step2;
3011
+ xni += xndt * delt + xnddt * step2;
3012
+ atime += delt;
3013
+ }
3014
+ }
3015
+
3016
+ nm = xni + xndt * ft + xnddt * ft * ft * 0.5;
3017
+ const xl = xli + xldot * ft + xndt * ft * ft * 0.5;
3018
+
3019
+ if (irez !== 1) {
3020
+ mm = xl - 2.0 * nodem + 2.0 * theta;
3021
+ dndt = nm - no;
3022
+ } else {
3023
+ mm = xl - nodem - argpm + theta;
3024
+ dndt = nm - no;
3025
+ }
3026
+ nm = no + dndt;
3027
+ }
3028
+
3029
+ return [em, argpm, inclm, mm, nodem, nm];
3030
+ }
3031
+
3032
+ /*
3033
+ * -----------------------------------------------------------------------------
3034
+ *
3035
+ * function getgravconst
3036
+ *
3037
+ * this function gets constants for the propagator. note that mu is identified to
3038
+ * facilitiate comparisons with newer models. the common useage is wgs72.
3039
+ *
3040
+ * author : david vallado 719-573-2600 21 jul 2006
3041
+ *
3042
+ * inputs :
3043
+ * whichconst - which set of constants to use wgs72old, wgs72, wgs84
3044
+ *
3045
+ * outputs :
3046
+ * tumin - minutes in one time unit
3047
+ * mu - earth gravitational parameter
3048
+ * radiusearthkm - radius of the earth in km
3049
+ * xke - reciprocal of tumin
3050
+ * j2, j3, j4 - un-normalized zonal harmonic values
3051
+ * j3oj2 - j3 divided by j2
3052
+ *
3053
+ * locals :
3054
+ *
3055
+ * coupling :
3056
+ * none
3057
+ *
3058
+ * references :
3059
+ * norad spacetrack report #3
3060
+ * vallado, crawford, hujsak, kelso 2006
3061
+ * ---------------------------------------------------------------------------
3062
+ */
3063
+ private static getgravconst_(whichconst: Sgp4GravConstants): {
3064
+ tumin: number;
3065
+ mus: number;
3066
+ radiusearthkm: number;
3067
+ xke: number;
3068
+ j2: number;
3069
+ j3: number;
3070
+ j4: number;
3071
+ j3oj2: number;
3072
+ } {
3073
+ let j2, j3, j3oj2, j4, mus, radiusearthkm, tumin, xke;
3074
+
3075
+ switch (whichconst) {
3076
+ // -- wgs-72 low precision str#3 constants --
3077
+ case 'wgs72old':
3078
+ mus = 398600.79964; // In km3 / s2
3079
+ radiusearthkm = 6378.135; // Km
3080
+ xke = 0.0743669161; // Reciprocal of tumin
3081
+ tumin = 1.0 / xke;
3082
+ j2 = 0.001082616;
3083
+ j3 = -0.00000253881;
3084
+ j4 = -0.00000165597;
3085
+ j3oj2 = j3 / j2;
3086
+ break;
3087
+ // ------------ wgs-72 constants ------------
3088
+ case 'wgs72':
3089
+ mus = 398600.8; // In km3 / s2
3090
+ radiusearthkm = 6378.135; // Km
3091
+ xke = 60.0 / Math.sqrt((radiusearthkm * radiusearthkm * radiusearthkm) / mus);
3092
+ tumin = 1.0 / xke;
3093
+ j2 = 0.001082616;
3094
+ j3 = -0.00000253881;
3095
+ j4 = -0.00000165597;
3096
+ j3oj2 = j3 / j2;
3097
+ break;
3098
+ case 'wgs84':
3099
+ // ------------ wgs-84 constants ------------
3100
+ mus = 398600.5; // In km3 / s2
3101
+ radiusearthkm = 6378.137; // Km
3102
+ xke = 60.0 / Math.sqrt((radiusearthkm * radiusearthkm * radiusearthkm) / mus);
3103
+ tumin = 1.0 / xke;
3104
+ j2 = 0.00108262998905;
3105
+ j3 = -0.00000253215306;
3106
+ j4 = -0.00000161098761;
3107
+ j3oj2 = j3 / j2;
3108
+ break;
3109
+ default:
3110
+ throw new Error(`unknown gravity option ${whichconst}`);
3111
+ }
3112
+
3113
+ return {
3114
+ tumin,
3115
+ mus,
3116
+ radiusearthkm,
3117
+ xke,
3118
+ j2,
3119
+ j3,
3120
+ j4,
3121
+ j3oj2,
3122
+ };
3123
+ }
3124
+
3125
+ /*
3126
+ *-----------------------------------------------------------------------------
3127
+ *
3128
+ * procedure initl
3129
+ *
3130
+ * this procedure initializes the sgp4 propagator. all the initialization is
3131
+ * consolidated here instead of having multiple loops inside other routines.
3132
+ *
3133
+ * author : david vallado 719-573-2600 28 jun 2005
3134
+ *
3135
+ * inputs :
3136
+ * satn - satellite number - not needed, placed in satrec
3137
+ * xke - reciprocal of tumin
3138
+ * j2 - j2 zonal harmonic
3139
+ * ecco - eccentricity 0.0 - 1.0
3140
+ * epoch - epoch time in days from jan 0, 1950. 0 hr
3141
+ * inclo - inclination of satellite
3142
+ * no - mean motion of satellite
3143
+ *
3144
+ * outputs :
3145
+ * ainv - 1.0 / a
3146
+ * ao - semi major axis
3147
+ * con41 -
3148
+ * con42 - 1.0 - 5.0 cos(i)
3149
+ * cosio - cosine of inclination
3150
+ * cosio2 - cosio squared
3151
+ * eccsq - eccentricity squared
3152
+ * method - flag for deep space 'd', 'n'
3153
+ * omeosq - 1.0 - ecco * ecco
3154
+ * posq - semi-parameter squared
3155
+ * rp - radius of perigee
3156
+ * rteosq - square root of (1.0 - ecco*ecco)
3157
+ * sinio - sine of inclination
3158
+ * gsto - gst at time of observation rad
3159
+ * no - mean motion of satellite
3160
+ *
3161
+ * locals :
3162
+ * ak -
3163
+ * d1 -
3164
+ * del -
3165
+ * adel -
3166
+ * po -
3167
+ *
3168
+ * coupling :
3169
+ * getgravconst- no longer used
3170
+ * gstime - find greenwich sidereal time from the julian date
3171
+ *
3172
+ * references :
3173
+ * hoots, roehrich, norad spacetrack report #3 1980
3174
+ * hoots, norad spacetrack report #6 1986
3175
+ * hoots, schumacher and glover 2004
3176
+ * vallado, crawford, hujsak, kelso 2006
3177
+ *----------------------------------------------------------------------------
3178
+ */
3179
+ private static initl_(
3180
+ satrec: SatelliteRecord,
3181
+ epoch: number,
3182
+ ): {
3183
+ no: number;
3184
+ ainv: number;
3185
+ ao: number;
3186
+ con41: number;
3187
+ con42: number;
3188
+ cosio: number;
3189
+ cosio2: number;
3190
+ eccsq: number;
3191
+ omeosq: number;
3192
+ posq: number;
3193
+ /** radius of perigee as a ratio */
3194
+ rp: number;
3195
+ rteosq: number;
3196
+ sinio: number;
3197
+ gsto: number;
3198
+ } {
3199
+ /*
3200
+ * Sgp4fix satn not needed. include in satrec in case needed later
3201
+ * int satn,
3202
+ * sgp4fix just pass in xke and j2
3203
+ * gravconsttype whichconst,
3204
+ */
3205
+ const { operationmode, ecco, inclo, xke, j2 } = satrec;
3206
+ let { no } = satrec;
3207
+
3208
+ /* --------------------- local variables ------------------------ */
3209
+ const x2o3 = 2.0 / 3.0;
3210
+
3211
+ // Sgp4fix use old way of finding gst
3212
+ /** Ootk -- Some variables imported from outside the class at the top */
3213
+
3214
+ /*
3215
+ * ----------------------- earth constants ---------------------
3216
+ * sgp4fix identify constants and allow alternate values
3217
+ * only xke and j2 are used here so pass them in directly
3218
+ * getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 )
3219
+ */
3220
+
3221
+ // ------------- calculate auxillary epoch quantities ----------
3222
+ const eccsq = ecco * ecco;
3223
+ const omeosq = 1.0 - eccsq;
3224
+ const rteosq = Math.sqrt(omeosq);
3225
+ const cosio = Math.cos(inclo);
3226
+ const cosio2 = cosio * cosio;
3227
+
3228
+ // ------------------ un-kozai the mean motion -----------------
3229
+ const ak = (xke / no) ** x2o3;
3230
+ const d1 = (0.75 * j2 * (3.0 * cosio2 - 1.0)) / (rteosq * omeosq);
3231
+ let delPrime = d1 / (ak * ak);
3232
+ const adel = ak * (1.0 - delPrime * delPrime - delPrime * (1.0 / 3.0 + (134.0 * delPrime * delPrime) / 81.0));
3233
+
3234
+ delPrime = d1 / (adel * adel);
3235
+ no /= 1.0 + delPrime;
3236
+
3237
+ const ao = (xke / no) ** x2o3;
3238
+ const sinio = Math.sin(inclo);
3239
+ const po = ao * omeosq;
3240
+ const con42 = 1.0 - 5.0 * cosio2;
3241
+ const con41 = -con42 - cosio2 - cosio2;
3242
+ const ainv = 1.0 / ao;
3243
+ const posq = po * po;
3244
+ const rp = ao * (1.0 - ecco);
3245
+
3246
+ // Sgp4fix modern approach to finding sidereal time
3247
+ /** Ootk -- Continue allowing AFSPC mode for SGP4 Validation */
3248
+ let gsto;
3249
+
3250
+ if (operationmode === Sgp4OpsMode.AFSPC) {
3251
+ /*
3252
+ * Sgp4fix use old way of finding gst
3253
+ * count integer number of days from 0 jan 1970
3254
+ */
3255
+ const ts70 = epoch - 7305.0;
3256
+ const ds70 = Math.floor(ts70 + 1.0e-8);
3257
+ const tfrac = ts70 - ds70;
3258
+
3259
+ // Find greenwich location at epoch
3260
+ const c1 = 1.72027916940703639e-2;
3261
+ const thgr70 = 1.7321343856509374;
3262
+ const fk5r = 5.07551419432269442e-15;
3263
+ const c1p2p = c1 + TAU;
3264
+
3265
+ gsto = (thgr70 + c1 * ds70 + c1p2p * tfrac + ts70 * ts70 * fk5r) % TAU;
3266
+ /* istanbul ignore next | This is no longer possible*/
3267
+ if (gsto < 0.0) {
3268
+ gsto += TAU;
3269
+ }
3270
+ } else {
3271
+ const jdut1 = epoch + 2433281.5;
3272
+ const tut1 = (jdut1 - 2451545.0) / 36525.0;
3273
+
3274
+ gsto = -6.2e-6 * tut1 * tut1 * tut1 + 0.093104 * tut1 * tut1 +
3275
+ (876600.0 * 3600 + 8640184.812866) * tut1 + 67310.54841; // Sec
3276
+
3277
+ gsto = ((gsto * DEG2RAD) / 240.0) % TAU; // 360/86400 = 1/240, to deg, to rad
3278
+
3279
+ // ------------------------ check quadrants ---------------------
3280
+ if (gsto < 0.0) {
3281
+ gsto += TAU;
3282
+ }
3283
+ }
3284
+
3285
+ return {
3286
+ no,
3287
+ ainv,
3288
+ ao,
3289
+ con41,
3290
+ con42,
3291
+ cosio,
3292
+ cosio2,
3293
+ eccsq,
3294
+ omeosq,
3295
+ posq,
3296
+ rp,
3297
+ rteosq,
3298
+ sinio,
3299
+ gsto,
3300
+ };
3301
+ }
3302
+
3303
+ /*
3304
+ *-----------------------------------------------------------------------------
3305
+ *
3306
+ * procedure sgp4init
3307
+ *
3308
+ * this procedure initializes variables for sgp4.
3309
+ *
3310
+ * author : david vallado 719-573-2600 28 jun 2005
3311
+ *
3312
+ * inputs :
3313
+ * opsmode - mode of operation afspc or improved 'a', 'i'
3314
+ * whichconst - which set of constants to use 72, 84
3315
+ * satn - satellite number
3316
+ * bstar - sgp4 type drag coefficient kg/m2er
3317
+ * ecco - eccentricity
3318
+ * epoch - epoch time in days from jan 0, 1950. 0 hr
3319
+ * argpo - argument of perigee (output if ds)
3320
+ * inclo - inclination
3321
+ * mo - mean anomaly (output if ds)
3322
+ * no - mean motion
3323
+ * nodeo - right ascension of ascending node
3324
+ *
3325
+ * outputs :
3326
+ * rec - common values for subsequent calls
3327
+ * return code - non-zero on error.
3328
+ * 1 - mean elements, ecc >= 1.0 or ecc < -0.001 or a < 0.95 er
3329
+ * 2 - mean motion less than 0.0
3330
+ * 3 - pert elements, ecc < 0.0 or ecc > 1.0
3331
+ * 4 - semi-latus rectum < 0.0
3332
+ * 5 - epoch elements are sub-orbital
3333
+ * 6 - satellite has decayed
3334
+ *
3335
+ * locals :
3336
+ * cnodm , snodm , cosim , sinim , cosomm , sinomm
3337
+ * cc1sq , cc2 , cc3
3338
+ * coef , coef1
3339
+ * cosio4 -
3340
+ * day -
3341
+ * dndt -
3342
+ * em - eccentricity
3343
+ * emsq - eccentricity squared
3344
+ * eeta -
3345
+ * etasq -
3346
+ * gam -
3347
+ * argpm - argument of perigee
3348
+ * nodem -
3349
+ * inclm - inclination
3350
+ * mm - mean anomaly
3351
+ * nm - mean motion
3352
+ * perige - perigee
3353
+ * PInvsq -
3354
+ * psisq -
3355
+ * qzms24 -
3356
+ * rtemsq -
3357
+ * s1, s2, s3, s4, s5, s6, s7 -
3358
+ * sfour -
3359
+ * ss1, ss2, ss3, ss4, ss5, ss6, ss7 -
3360
+ * sz1, sz2, sz3
3361
+ * sz11, sz12, sz13, sz21, sz22, sz23, sz31, sz32, sz33 -
3362
+ * tc -
3363
+ * temp -
3364
+ * temp1, temp2, temp3 -
3365
+ * tsi -
3366
+ * xPIdot -
3367
+ * xhdot1 -
3368
+ * z1, z2, z3 -
3369
+ * z11, z12, z13, z21, z22, z23, z31, z32, z33 -
3370
+ *
3371
+ * coupling :
3372
+ * getgravconst-
3373
+ * initl -
3374
+ * dscom -
3375
+ * dpper -
3376
+ * dsinit -
3377
+ * sgp4 -
3378
+ *
3379
+ * references :
3380
+ * hoots, roehrich, norad spacetrack report #3 1980
3381
+ * hoots, norad spacetrack report #6 1986
3382
+ * hoots, schumacher and glover 2004
3383
+ * vallado, crawford, hujsak, kelso 2006
3384
+ *----------------------------------------------------------------------------
3385
+ */
3386
+ private static sgp4init_(
3387
+ satrec: SatelliteRecord,
3388
+ options: {
3389
+ whichconst?: Sgp4GravConstants;
3390
+ opsmode?: Sgp4OpsMode;
3391
+ satn?: string;
3392
+ epoch: number;
3393
+ xbstar: number;
3394
+ xecco: number;
3395
+ xargpo: number;
3396
+ xinclo: number;
3397
+ xndot: number;
3398
+ xnddot: number;
3399
+ xmo: number;
3400
+ xno: number;
3401
+ xnodeo: number;
3402
+ },
3403
+ ): void {
3404
+ const {
3405
+ whichconst = Sgp4GravConstants.wgs72,
3406
+ opsmode = Sgp4OpsMode.IMPROVED,
3407
+ satn = satrec.satnum,
3408
+ epoch,
3409
+ xbstar,
3410
+ xecco,
3411
+ xargpo,
3412
+ xinclo,
3413
+ xndot,
3414
+ xnddot,
3415
+ xmo,
3416
+ xno,
3417
+ xnodeo,
3418
+ } = options;
3419
+
3420
+ /* ------------------------ initialization --------------------- */
3421
+ /*
3422
+ * Sgp4fix divisor for divide by zero check on inclination
3423
+ * the old check used 1.0 + Math.cos(PI-1.0e-9), but then compared it to
3424
+ * 1.5 e-12, so the threshold was changed to 1.5e-12 for consistency
3425
+ */
3426
+
3427
+ // ----------- set all near earth variables to zero ------------
3428
+ satrec.isimp = false;
3429
+ satrec.method = Sgp4Methods.NEAR_EARTH;
3430
+ satrec.aycof = 0.0;
3431
+ satrec.con41 = 0.0;
3432
+ satrec.cc1 = 0.0;
3433
+ satrec.cc4 = 0.0;
3434
+ satrec.cc5 = 0.0;
3435
+ satrec.d2 = 0.0;
3436
+ satrec.d3 = 0.0;
3437
+ satrec.d4 = 0.0;
3438
+ satrec.delmo = 0.0;
3439
+ satrec.eta = 0.0;
3440
+ satrec.argpdot = 0.0;
3441
+ satrec.omgcof = 0.0;
3442
+ satrec.sinmao = 0.0;
3443
+ satrec.t = 0.0;
3444
+ satrec.t2cof = 0.0;
3445
+ satrec.t3cof = 0.0;
3446
+ satrec.t4cof = 0.0;
3447
+ satrec.t5cof = 0.0;
3448
+ satrec.x1mth2 = 0.0;
3449
+ satrec.x7thm1 = 0.0;
3450
+ satrec.mdot = 0.0;
3451
+ satrec.nodedot = 0.0;
3452
+ satrec.xlcof = 0.0;
3453
+ satrec.xmcof = 0.0;
3454
+ satrec.nodecf = 0.0;
3455
+
3456
+ // ----------- set all deep space variables to zero ------------
3457
+ satrec.irez = 0;
3458
+ satrec.d2201 = 0.0;
3459
+ satrec.d2211 = 0.0;
3460
+ satrec.d3210 = 0.0;
3461
+ satrec.d3222 = 0.0;
3462
+ satrec.d4410 = 0.0;
3463
+ satrec.d4422 = 0.0;
3464
+ satrec.d5220 = 0.0;
3465
+ satrec.d5232 = 0.0;
3466
+ satrec.d5421 = 0.0;
3467
+ satrec.d5433 = 0.0;
3468
+ satrec.dedt = 0.0;
3469
+ satrec.del1 = 0.0;
3470
+ satrec.del2 = 0.0;
3471
+ satrec.del3 = 0.0;
3472
+ satrec.didt = 0.0;
3473
+ satrec.dmdt = 0.0;
3474
+ satrec.dnodt = 0.0;
3475
+ satrec.domdt = 0.0;
3476
+ satrec.e3 = 0.0;
3477
+ satrec.ee2 = 0.0;
3478
+ satrec.peo = 0.0;
3479
+ satrec.pgho = 0.0;
3480
+ satrec.pho = 0.0;
3481
+ satrec.PInco = 0.0;
3482
+ satrec.plo = 0.0;
3483
+ satrec.se2 = 0.0;
3484
+ satrec.se3 = 0.0;
3485
+ satrec.sgh2 = 0.0;
3486
+ satrec.sgh3 = 0.0;
3487
+ satrec.sgh4 = 0.0;
3488
+ satrec.sh2 = 0.0;
3489
+ satrec.sh3 = 0.0;
3490
+ satrec.si2 = 0.0;
3491
+ satrec.si3 = 0.0;
3492
+ satrec.sl2 = 0.0;
3493
+ satrec.sl3 = 0.0;
3494
+ satrec.sl4 = 0.0;
3495
+ satrec.gsto = 0.0;
3496
+ satrec.xfact = 0.0;
3497
+ satrec.xgh2 = 0.0;
3498
+ satrec.xgh3 = 0.0;
3499
+ satrec.xgh4 = 0.0;
3500
+ satrec.xh2 = 0.0;
3501
+ satrec.xh3 = 0.0;
3502
+ satrec.xi2 = 0.0;
3503
+ satrec.xi3 = 0.0;
3504
+ satrec.xl2 = 0.0;
3505
+ satrec.xl3 = 0.0;
3506
+ satrec.xl4 = 0.0;
3507
+ satrec.xlamo = 0.0;
3508
+ satrec.zmol = 0.0;
3509
+ satrec.zmos = 0.0;
3510
+ satrec.atime = 0.0;
3511
+ satrec.xli = 0.0;
3512
+ satrec.xni = 0.0;
3513
+
3514
+ /* ------------------------ earth constants ----------------------- */
3515
+ /*
3516
+ * Sgp4fix identify constants and allow alternate values
3517
+ * this is now the only call for the constants
3518
+ */
3519
+ const gravResults = Sgp4.getgravconst_(whichconst);
3520
+
3521
+ satrec.tumin = gravResults.tumin;
3522
+ satrec.mus = gravResults.mus;
3523
+ satrec.radiusearthkm = gravResults.radiusearthkm;
3524
+ satrec.xke = gravResults.xke;
3525
+ satrec.j2 = gravResults.j2;
3526
+ satrec.j3 = gravResults.j3;
3527
+ satrec.j4 = gravResults.j4;
3528
+ satrec.j3oj2 = gravResults.j3oj2;
3529
+ satrec.vkmpersec = (satrec.radiusearthkm * satrec.xke) / 60.0;
3530
+ const { j2 } = gravResults;
3531
+ const { j4 } = gravResults;
3532
+ const { xke } = gravResults;
3533
+ const { j3oj2 } = gravResults;
3534
+
3535
+ // -------------------------------------------------------------------------
3536
+
3537
+ satrec.error = Sgp4ErrorCode.NO_ERROR;
3538
+ satrec.operationmode = opsmode;
3539
+
3540
+ // New alpha5 or 9-digit number
3541
+ /**
3542
+ * Ootk -- Using JS code for string manipulation but same effect
3543
+ * Ex. A2525 = 102525
3544
+ * Ex. Z1234 = 351234
3545
+ */
3546
+
3547
+ satrec.satnum = Tle.convertA5to6Digit(satn);
3548
+
3549
+ /*
3550
+ * Sgp4fix - note the following variables are also passed directly via satrec.
3551
+ * it is possible to streamline the sgp4init call by deleting the "x"
3552
+ * variables, but the user would need to set the satrec.* values first. we
3553
+ * include the additional assignments in case twoline2rv is not used.
3554
+ */
3555
+ satrec.bstar = xbstar;
3556
+ // Sgp4fix allow additional parameters in the struct
3557
+ satrec.ndot = xndot;
3558
+ satrec.nddot = xnddot;
3559
+ satrec.ecco = xecco;
3560
+ satrec.argpo = xargpo;
3561
+ satrec.inclo = xinclo;
3562
+ satrec.mo = xmo;
3563
+ // Sgp4fix rename variables to clarify which mean motion is intended
3564
+ satrec.no = xno;
3565
+ satrec.nodeo = xnodeo;
3566
+
3567
+ /*
3568
+ * Single averaged mean elements
3569
+ * satrec.am = satrec.em = satrec.im = satrec.Om = satrec.mm = satrec.nm = 0.0;
3570
+ */
3571
+
3572
+ /*
3573
+ * ------------------------ earth constants -----------------------
3574
+ * sgp4fix identify constants and allow alternate values
3575
+ * getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
3576
+ */
3577
+ const ss = 78.0 / satrec.radiusearthkm + 1.0;
3578
+ // Sgp4fix use multiply for speed instead of pow
3579
+ const qzms2ttemp = (120.0 - 78.0) / satrec.radiusearthkm;
3580
+ const qzms2t = qzms2ttemp * qzms2ttemp * qzms2ttemp * qzms2ttemp;
3581
+
3582
+ satrec.init = true;
3583
+ satrec.t = 0.0;
3584
+
3585
+ // Sgp4fix remove satn as it is not needed in initl
3586
+ const initlResult = Sgp4.initl_(satrec, epoch);
3587
+
3588
+ const { ao, con42, cosio, cosio2, eccsq, omeosq, posq, rp, rteosq, sinio } = initlResult;
3589
+
3590
+ satrec.no = initlResult.no;
3591
+ satrec.con41 = initlResult.con41;
3592
+ satrec.gsto = initlResult.gsto;
3593
+ satrec.a = (satrec.no * satrec.tumin) ** (-2.0 / 3.0);
3594
+ satrec.alta = satrec.a * (1.0 + satrec.ecco) - 1.0;
3595
+ satrec.altp = satrec.a * (1.0 - satrec.ecco) - 1.0;
3596
+ satrec.error = Sgp4ErrorCode.NO_ERROR;
3597
+
3598
+ /*
3599
+ * Sgp4fix remove this check as it is unnecessary
3600
+ * the mrt check in sgp4 handles decaying satellite cases even if the starting
3601
+ * condition is below the surface of te earth
3602
+ * if (rp < 1.0)
3603
+ * {
3604
+ * printf("// *** satn%d epoch elts sub-orbital ***\n", satn);
3605
+ * satrec.error = 5;
3606
+ * }
3607
+ */
3608
+
3609
+ if (omeosq >= 0.0 || satrec.no >= 0.0) {
3610
+ satrec.isimp = false;
3611
+ if (rp < 220.0 / satrec.radiusearthkm + 1.0) {
3612
+ satrec.isimp = true;
3613
+ }
3614
+ let sfour = ss;
3615
+ let qzms24 = qzms2t;
3616
+ const perigee = (rp - 1.0) * satrec.radiusearthkm;
3617
+
3618
+ // - for perigees below 156 km, s and qoms2t are altered -
3619
+ if (perigee < 156.0) {
3620
+ sfour = perigee - 78.0;
3621
+ if (perigee < 98.0) {
3622
+ sfour = 20.0;
3623
+ }
3624
+ // Sgp4fix use multiply for speed instead of pow
3625
+ const qzms24temp = (120.0 - sfour) / satrec.radiusearthkm;
3626
+
3627
+ qzms24 = qzms24temp * qzms24temp * qzms24temp * qzms24temp;
3628
+ sfour = sfour / satrec.radiusearthkm + 1.0;
3629
+ }
3630
+ const PInvsq = 1.0 / posq;
3631
+
3632
+ const tsi = 1.0 / (ao - sfour);
3633
+
3634
+ satrec.eta = ao * satrec.ecco * tsi;
3635
+ const etasq = satrec.eta * satrec.eta;
3636
+ const eeta = satrec.ecco * satrec.eta;
3637
+ const psisq = Math.abs(1.0 - etasq);
3638
+ const coef = qzms24 * tsi ** 4.0;
3639
+ const coef1 = coef / psisq ** 3.5;
3640
+ const cc2 =
3641
+ coef1 *
3642
+ satrec.no *
3643
+ (ao * (1.0 + 1.5 * etasq + eeta * (4.0 + etasq)) +
3644
+ ((0.375 * j2 * tsi) / psisq) * satrec.con41 * (8.0 + 3.0 * etasq * (8.0 + etasq)));
3645
+
3646
+ satrec.cc1 = satrec.bstar * cc2;
3647
+ let cc3 = 0.0;
3648
+
3649
+ if (satrec.ecco > 1.0e-4) {
3650
+ cc3 = (-2.0 * coef * tsi * j3oj2 * satrec.no * sinio) / satrec.ecco;
3651
+ }
3652
+ satrec.x1mth2 = 1.0 - cosio2;
3653
+ satrec.cc4 =
3654
+ 2.0 *
3655
+ satrec.no *
3656
+ coef1 *
3657
+ ao *
3658
+ omeosq *
3659
+ (satrec.eta * (2.0 + 0.5 * etasq) +
3660
+ satrec.ecco * (0.5 + 2.0 * etasq) -
3661
+ ((j2 * tsi) / (ao * psisq)) *
3662
+ (-3.0 * satrec.con41 * (1.0 - 2.0 * eeta + etasq * (1.5 - 0.5 * eeta)) +
3663
+ 0.75 * satrec.x1mth2 * (2.0 * etasq - eeta * (1.0 + etasq)) * Math.cos(2.0 * satrec.argpo)));
3664
+ satrec.cc5 = 2.0 * coef1 * ao * omeosq * (1.0 + 2.75 * (etasq + eeta) + eeta * etasq);
3665
+ const cosio4 = cosio2 * cosio2;
3666
+ const temp1 = 1.5 * j2 * PInvsq * satrec.no;
3667
+ const temp2 = 0.5 * temp1 * j2 * PInvsq;
3668
+ const temp3 = -0.46875 * j4 * PInvsq * PInvsq * satrec.no;
3669
+
3670
+ satrec.mdot =
3671
+ satrec.no +
3672
+ 0.5 * temp1 * rteosq * satrec.con41 +
3673
+ 0.0625 * temp2 * rteosq * (13.0 - 78.0 * cosio2 + 137.0 * cosio4);
3674
+ satrec.argpdot =
3675
+ -0.5 * temp1 * con42 +
3676
+ 0.0625 * temp2 * (7.0 - 114.0 * cosio2 + 395.0 * cosio4) +
3677
+ temp3 * (3.0 - 36.0 * cosio2 + 49.0 * cosio4);
3678
+ const xhdot1 = -temp1 * cosio;
3679
+
3680
+ satrec.nodedot = xhdot1 + (0.5 * temp2 * (4.0 - 19.0 * cosio2) + 2.0 * temp3 * (3.0 - 7.0 * cosio2)) * cosio;
3681
+ const xPIdot = satrec.argpdot + satrec.nodedot;
3682
+
3683
+ satrec.omgcof = satrec.bstar * cc3 * Math.cos(satrec.argpo);
3684
+ satrec.xmcof = 0.0;
3685
+ if (satrec.ecco > 1.0e-4) {
3686
+ satrec.xmcof = (-x2o3 * coef * satrec.bstar) / eeta;
3687
+ }
3688
+ satrec.nodecf = 3.5 * omeosq * xhdot1 * satrec.cc1;
3689
+ satrec.t2cof = 1.5 * satrec.cc1;
3690
+
3691
+ // Sgp4fix for divide by zero with xinco = 180 deg
3692
+ if (Math.abs(cosio + 1.0) > 1.5e-12) {
3693
+ satrec.xlcof = (-0.25 * j3oj2 * sinio * (3.0 + 5.0 * cosio)) / (1.0 + cosio);
3694
+ } else {
3695
+ satrec.xlcof = (-0.25 * j3oj2 * sinio * (3.0 + 5.0 * cosio)) / temp4;
3696
+ }
3697
+ satrec.aycof = -0.5 * j3oj2 * sinio;
3698
+
3699
+ // Sgp4fix use multiply for speed instead of pow
3700
+ const delmotemp = 1.0 + satrec.eta * Math.cos(satrec.mo);
3701
+
3702
+ satrec.delmo = delmotemp * delmotemp * delmotemp;
3703
+ satrec.sinmao = Math.sin(satrec.mo);
3704
+ satrec.x7thm1 = 7.0 * cosio2 - 1.0;
3705
+
3706
+ // --------------- deep space initialization -------------
3707
+ if (TAU / satrec.no >= 225.0) {
3708
+ satrec.method = Sgp4Methods.DEEP_SPACE;
3709
+ satrec.isimp = true;
3710
+ const tc = 0.0;
3711
+ const inclm = satrec.inclo;
3712
+
3713
+ const dscomOptions = {
3714
+ epoch,
3715
+ ep: satrec.ecco,
3716
+ argpp: satrec.argpo,
3717
+ tc,
3718
+ inclp: satrec.inclo,
3719
+ nodep: satrec.nodeo,
3720
+ np: satrec.no,
3721
+ e3: satrec.e3,
3722
+ ee2: satrec.ee2,
3723
+ peo: satrec.peo,
3724
+ pgho: satrec.pgho,
3725
+ pho: satrec.pho,
3726
+ PInco: satrec.PInco,
3727
+ plo: satrec.plo,
3728
+ se2: satrec.se2,
3729
+ se3: satrec.se3,
3730
+ sgh2: satrec.sgh2,
3731
+ sgh3: satrec.sgh3,
3732
+ sgh4: satrec.sgh4,
3733
+ sh2: satrec.sh2,
3734
+ sh3: satrec.sh3,
3735
+ si2: satrec.si2,
3736
+ si3: satrec.si3,
3737
+ sl2: satrec.sl2,
3738
+ sl3: satrec.sl3,
3739
+ sl4: satrec.sl4,
3740
+ xgh2: satrec.xgh2,
3741
+ xgh3: satrec.xgh3,
3742
+ xgh4: satrec.xgh4,
3743
+ xh2: satrec.xh2,
3744
+ xh3: satrec.xh3,
3745
+ xi2: satrec.xi2,
3746
+ xi3: satrec.xi3,
3747
+ xl2: satrec.xl2,
3748
+ xl3: satrec.xl3,
3749
+ xl4: satrec.xl4,
3750
+ zmol: satrec.zmol,
3751
+ zmos: satrec.zmos,
3752
+ };
3753
+
3754
+ const dscomResult = Sgp4.dscom_(dscomOptions);
3755
+
3756
+ satrec.e3 = dscomResult.e3;
3757
+ satrec.ee2 = dscomResult.ee2;
3758
+
3759
+ satrec.peo = dscomResult.peo;
3760
+ satrec.pgho = dscomResult.pgho;
3761
+ satrec.pho = dscomResult.pho;
3762
+
3763
+ satrec.PInco = dscomResult.PInco;
3764
+ satrec.plo = dscomResult.plo;
3765
+ satrec.se2 = dscomResult.se2;
3766
+ satrec.se3 = dscomResult.se3;
3767
+
3768
+ satrec.sgh2 = dscomResult.sgh2;
3769
+ satrec.sgh3 = dscomResult.sgh3;
3770
+ satrec.sgh4 = dscomResult.sgh4;
3771
+ satrec.sh2 = dscomResult.sh2;
3772
+ satrec.sh3 = dscomResult.sh3;
3773
+
3774
+ satrec.si2 = dscomResult.si2;
3775
+ satrec.si3 = dscomResult.si3;
3776
+ satrec.sl2 = dscomResult.sl2;
3777
+ satrec.sl3 = dscomResult.sl3;
3778
+ satrec.sl4 = dscomResult.sl4;
3779
+
3780
+ const {
3781
+ sinim,
3782
+ cosim,
3783
+ em,
3784
+ emsq,
3785
+ s1,
3786
+ s2,
3787
+ s3,
3788
+ s4,
3789
+ s5,
3790
+ ss1,
3791
+ ss2,
3792
+ ss3,
3793
+ ss4,
3794
+ ss5,
3795
+ sz1,
3796
+ sz3,
3797
+ sz11,
3798
+ sz13,
3799
+ sz21,
3800
+ sz23,
3801
+ sz31,
3802
+ sz33,
3803
+ } = dscomResult;
3804
+
3805
+ satrec.xgh2 = dscomResult.xgh2;
3806
+ satrec.xgh3 = dscomResult.xgh3;
3807
+ satrec.xgh4 = dscomResult.xgh4;
3808
+ satrec.xh2 = dscomResult.xh2;
3809
+ satrec.xh3 = dscomResult.xh3;
3810
+ satrec.xi2 = dscomResult.xi2;
3811
+ satrec.xi3 = dscomResult.xi3;
3812
+ satrec.xl2 = dscomResult.xl2;
3813
+ satrec.xl3 = dscomResult.xl3;
3814
+ satrec.xl4 = dscomResult.xl4;
3815
+ satrec.zmol = dscomResult.zmol;
3816
+ satrec.zmos = dscomResult.zmos;
3817
+
3818
+ const { nm, z1, z3, z11, z13, z21, z23, z31, z33 } = dscomResult;
3819
+
3820
+ const dpperOptions = {
3821
+ inclo: inclm,
3822
+ init: satrec.init,
3823
+ ep: satrec.ecco,
3824
+ inclp: satrec.inclo,
3825
+ nodep: satrec.nodeo,
3826
+ argpp: satrec.argpo,
3827
+ mp: satrec.mo,
3828
+ opsmode: satrec.operationmode,
3829
+ satrec,
3830
+ };
3831
+
3832
+ const dpperResult = Sgp4.dpper_(dpperOptions);
3833
+
3834
+ satrec.ecco = dpperResult.ep;
3835
+ satrec.inclo = dpperResult.inclp;
3836
+ satrec.nodeo = dpperResult.nodep;
3837
+ satrec.argpo = dpperResult.argpp;
3838
+ satrec.mo = dpperResult.mp;
3839
+
3840
+ const argpm = 0.0;
3841
+ const nodem = 0.0;
3842
+ const mm = 0.0;
3843
+
3844
+ const dsinitOptions = {
3845
+ xke,
3846
+ cosim,
3847
+ emsq,
3848
+ argpo: satrec.argpo,
3849
+ s1,
3850
+ s2,
3851
+ s3,
3852
+ s4,
3853
+ s5,
3854
+ sinim,
3855
+ ss1,
3856
+ ss2,
3857
+ ss3,
3858
+ ss4,
3859
+ ss5,
3860
+ sz1,
3861
+ sz3,
3862
+ sz11,
3863
+ sz13,
3864
+ sz21,
3865
+ sz23,
3866
+ sz31,
3867
+ sz33,
3868
+ t: satrec.t,
3869
+ tc,
3870
+ gsto: satrec.gsto,
3871
+ mo: satrec.mo,
3872
+ mdot: satrec.mdot,
3873
+ no: satrec.no,
3874
+ nodeo: satrec.nodeo,
3875
+ nodedot: satrec.nodedot,
3876
+ xPIdot,
3877
+ z1,
3878
+ z3,
3879
+ z11,
3880
+ z13,
3881
+ z21,
3882
+ z23,
3883
+ z31,
3884
+ z33,
3885
+ ecco: satrec.ecco,
3886
+ eccsq,
3887
+ em,
3888
+ argpm,
3889
+ inclm,
3890
+ mm,
3891
+ nm,
3892
+ nodem,
3893
+ irez: satrec.irez,
3894
+ atime: satrec.atime,
3895
+ d2201: satrec.d2201,
3896
+ d2211: satrec.d2211,
3897
+ d3210: satrec.d3210,
3898
+ d3222: satrec.d3222,
3899
+ d4410: satrec.d4410,
3900
+ d4422: satrec.d4422,
3901
+ d5220: satrec.d5220,
3902
+ d5232: satrec.d5232,
3903
+ d5421: satrec.d5421,
3904
+ d5433: satrec.d5433,
3905
+ dedt: satrec.dedt,
3906
+ didt: satrec.didt,
3907
+ dmdt: satrec.dmdt,
3908
+ dnodt: satrec.dnodt,
3909
+ domdt: satrec.domdt,
3910
+ del1: satrec.del1,
3911
+ del2: satrec.del2,
3912
+ del3: satrec.del3,
3913
+ xfact: satrec.xfact,
3914
+ xlamo: satrec.xlamo,
3915
+ xli: satrec.xli,
3916
+ xni: satrec.xni,
3917
+ };
3918
+
3919
+ const dsinitResult = Sgp4.dsinit_(dsinitOptions as DsInitParams);
3920
+
3921
+ satrec.irez = dsinitResult.irez;
3922
+ satrec.atime = dsinitResult.atime;
3923
+ satrec.d2201 = dsinitResult.d2201;
3924
+ satrec.d2211 = dsinitResult.d2211;
3925
+
3926
+ satrec.d3210 = dsinitResult.d3210;
3927
+ satrec.d3222 = dsinitResult.d3222;
3928
+ satrec.d4410 = dsinitResult.d4410;
3929
+ satrec.d4422 = dsinitResult.d4422;
3930
+ satrec.d5220 = dsinitResult.d5220;
3931
+
3932
+ satrec.d5232 = dsinitResult.d5232;
3933
+ satrec.d5421 = dsinitResult.d5421;
3934
+ satrec.d5433 = dsinitResult.d5433;
3935
+ satrec.dedt = dsinitResult.dedt;
3936
+ satrec.didt = dsinitResult.didt;
3937
+
3938
+ satrec.dmdt = dsinitResult.dmdt;
3939
+ satrec.dnodt = dsinitResult.dnodt;
3940
+ satrec.domdt = dsinitResult.domdt;
3941
+ satrec.del1 = dsinitResult.del1;
3942
+
3943
+ satrec.del2 = dsinitResult.del2;
3944
+ satrec.del3 = dsinitResult.del3;
3945
+ satrec.xfact = dsinitResult.xfact;
3946
+ satrec.xlamo = dsinitResult.xlamo;
3947
+ satrec.xli = dsinitResult.xli;
3948
+
3949
+ satrec.xni = dsinitResult.xni;
3950
+ }
3951
+
3952
+ // ----------- set variables if not deep space -----------
3953
+ if (!satrec.isimp) {
3954
+ const cc1sq = satrec.cc1 * satrec.cc1;
3955
+
3956
+ satrec.d2 = 4.0 * ao * tsi * cc1sq;
3957
+ const temp = (satrec.d2 * tsi * satrec.cc1) / 3.0;
3958
+
3959
+ satrec.d3 = (17.0 * ao + sfour) * temp;
3960
+ satrec.d4 = 0.5 * temp * ao * tsi * (221.0 * ao + 31.0 * sfour) * satrec.cc1;
3961
+ satrec.t3cof = satrec.d2 + 2.0 * cc1sq;
3962
+ satrec.t4cof = 0.25 * (3.0 * satrec.d3 + satrec.cc1 * (12.0 * satrec.d2 + 10.0 * cc1sq));
3963
+ satrec.t5cof =
3964
+ 0.2 *
3965
+ (3.0 * satrec.d4 +
3966
+ 12.0 * satrec.cc1 * satrec.d3 +
3967
+ 6.0 * satrec.d2 * satrec.d2 +
3968
+ 15.0 * cc1sq * (2.0 * satrec.d2 + cc1sq));
3969
+ } // If omeosq = 0 ...
3970
+
3971
+ /* Finally propogate to zero epoch to initialize all others. */
3972
+ /*
3973
+ * Sgp4fix take out check to let satellites process until they are actually below earth surface
3974
+ * if(satrec.error == 0)
3975
+ */
3976
+ }
3977
+ Sgp4.propagate(satrec, 0);
3978
+
3979
+ satrec.init = false;
3980
+
3981
+ /*
3982
+ * Sgp4fix return boolean. satrec.error contains any error codes
3983
+ * return satrec; -- no reason to return anything in JS
3984
+ */
3985
+ }
3986
+ }