UNPKG

ootk-core

Version:

Orbital Object Toolkit. A modern typed replacement for satellite.js including SGP4 propagation, TLE parsing, Sun and Moon calculations, and more.

215 lines 8.75 kB
/** * @author Theodore Kruczek. * @license MIT * @copyright (c) 2022-2025 Theodore Kruczek Permission is * hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the * Software without restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* eslint-disable no-undefined */ import { ITRF } from '../coordinate/ITRF.js'; import { AngularDistanceMethod } from '../enums/AngularDistanceMethod.js'; import { Vector3D } from '../operations/Vector3D.js'; import { DEG2RAD, halfPi, RAD2DEG, TAU } from '../utils/constants.js'; import { angularDistance } from '../utils/functions.js'; // / Range, azimuth, and elevation. export class RAE { epoch; rng; azRad; elRad; rngRate; azRateRad; elRateRad; constructor(epoch, rng, azRad, elRad, /** The range rate of the satellite relative to the observer in kilometers per second. */ rngRate, /** The azimuth rate of the satellite relative to the observer in radians per second. */ azRateRad, /** The elevation rate of the satellite relative to the observer in radians per second. */ elRateRad) { this.epoch = epoch; this.rng = rng; this.azRad = azRad; this.elRad = elRad; this.rngRate = rngRate; this.azRateRad = azRateRad; this.elRateRad = elRateRad; // Do nothing } // / Create a new [Razel] object, using degrees for the angular values. static fromDegrees(epoch, range, azimuth, elevation, rangeRate, azimuthRate, elevationRate) { const azimuthRateRad = azimuthRate ? azimuthRate * DEG2RAD : undefined; const elevationRateRad = elevationRate ? elevationRate * DEG2RAD : undefined; return new RAE(epoch, range, (azimuth * DEG2RAD), (elevation * DEG2RAD), rangeRate, azimuthRateRad, elevationRateRad); } /** * Create a [Razel] object from an inertial [state] and [site] vector. * @param state The inertial [state] vector. * @param site The observer [site] vector. * @returns A new [Razel] object. */ static fromStateVector(state, site) { const stateEcef = state.toITRF(); const siteEcef = site.toITRF(); const po2 = halfPi; const r = stateEcef.position.subtract(siteEcef.position); const rDot = stateEcef.velocity; const geo = siteEcef.toGeodetic(); const p = r.rotZ(geo.lon).rotY((po2 - geo.lat)); const pDot = rDot.rotZ(geo.lon).rotY((po2 - geo.lat)); const pS = p.x; const pE = p.y; const pZ = p.z; const pSDot = pDot.x; const pEDot = pDot.y; const pZDot = pDot.z; const pMag = p.magnitude(); const pSEMag = Math.sqrt(pS * pS + pE * pE); const elevation = Math.asin(pZ / pMag); let azimuth; if (elevation !== po2) { azimuth = Math.atan2(-pE, pS) + Math.PI; } else { azimuth = Math.atan2(-pEDot, pSDot) + Math.PI; } const rangeRate = p.dot(pDot) / pMag; const azimuthRate = (pSDot * pE - pEDot * pS) / (pS * pS + pE * pE); const elevationRate = (pZDot - rangeRate * Math.sin(elevation)) / pSEMag; return new RAE(state.epoch, pMag, (azimuth % TAU), elevation, rangeRate, azimuthRate, elevationRate); } /** * Gets the azimuth in degrees. * @returns The azimuth in degrees. */ get az() { return this.azRad * RAD2DEG; } /** * Gets the elevation angle in degrees. * @returns The elevation angle in degrees. */ get el() { return this.elRad * RAD2DEG; } /** * Gets the azimuth rate in degrees per second. * @returns The azimuth rate in degrees per second, or undefined if it is not available. */ get azRate() { return this.azRateRad ? this.azRateRad * RAD2DEG : undefined; } /** * Gets the elevation rate in degrees per second. * @returns The elevation rate in degrees per second, or undefined if the elevation rate is not set. */ get elRate() { return this.elRateRad ? this.elRateRad * RAD2DEG : undefined; } toString() { return [ '[RazEl]', ` Epoch: ${this.epoch}`, ` Azimuth: ${this.az.toFixed(4)}°`, ` Elevation: ${this.el.toFixed(4)}°`, ` Range: ${this.rng.toFixed(3)} km`, ].join('\n'); } /** * Return the position relative to the observer [site]. * * An optional azimuth [az] _(rad)_ and elevation [el] _(rad)_ value can be * passed to override the values contained in this observation. * @param site The observer [site]. * @param azRad Azimuth _(rad)_. * @param elRad Elevation _(rad)_. * @returns A [Vector3D] object. */ position(site, azRad, elRad) { const ecef = site.toITRF(); const geo = ecef.toGeodetic(); const po2 = halfPi; const newAz = azRad ?? this.azRad; const newEl = elRad ?? this.elRad; const sAz = Math.sin(newAz); const cAz = Math.cos(newAz); const sEl = Math.sin(newEl); const cEl = Math.cos(newEl); const pSez = new Vector3D((-this.rng * cEl * cAz), (this.rng * cEl * sAz), (this.rng * sEl)); const rEcef = pSez .rotY(-(po2 - geo.lat)) .rotZ(-geo.lon) .add(ecef.position); return new ITRF(this.epoch, rEcef, Vector3D.origin).toJ2000().position; } /** * Convert this observation into a [J2000] state vector. * * This will throw an error if the [rangeRate], [elevationRate], or * [azimuthRate] are not defined. * @param site The observer [site]. * @returns A [J2000] state vector. */ toStateVector(site) { // If the rates are not defined then assume stationary this.rngRate ??= 0; this.elRateRad ??= 0; this.azRateRad ??= 0; const ecef = site.toITRF(); const geo = ecef.toGeodetic(); const po2 = halfPi; const sAz = Math.sin(this.azRad); const cAz = Math.cos(this.azRad); const sEl = Math.sin(this.elRad); const cEl = Math.cos(this.elRad); const pSez = new Vector3D((-this.rng * cEl * cAz), (this.rng * cEl * sAz), (this.rng * sEl)); const pDotSez = new Vector3D((-this.rngRate * cEl * cAz + this.rng * sEl * cAz * this.elRateRad + this.rng * cEl * sAz * this.azRateRad), (this.rngRate * cEl * sAz - this.rng * sEl * sAz * this.elRateRad + this.rng * cEl * cAz * this.azRateRad), (this.rngRate * sEl + this.rng * cEl * this.elRateRad)); const pEcef = pSez.rotY(-(po2 - geo.lat)).rotZ(-geo.lon); const pDotEcef = pDotSez .rotY(-(po2 - geo.lat)) // TODO: #13 Intermediate unit type is incorrect. .rotZ(-geo.lon); const rEcef = pEcef.add(ecef.position); return new ITRF(this.epoch, rEcef, pDotEcef).toJ2000(); } /** * Calculate the angular distance _(rad)_ between this and another [Razel] * object. * @param razel The other [Razel] object. * @param method The angular distance method to use. * @returns The angular distance _(rad)_. */ angle(razel, method = AngularDistanceMethod.Cosine) { return angularDistance(this.azRad, this.elRad, razel.azRad, razel.elRad, method); } /** * Calculate the angular distance _(°)_ between this and another [Razel] * object. * @param razel The other [Razel] object. * @param method The angular distance method to use. * @returns The angular distance _(°)_. */ angleDegrees(razel, method = AngularDistanceMethod.Cosine) { return this.angle(razel, method) * RAD2DEG; } } //# sourceMappingURL=RAE.js.map