UNPKG

ootk

Version:

Orbital Object Toolkit including Multiple Propagators, Initial Orbit Determination, and Maneuver Calculations.

69 lines 2.6 kB
/** * @author @thkruz Theodore Kruczek * @license AGPL-3.0-or-later * @copyright (c) 2025 Kruczek Labs LLC * * Orbital Object ToolKit is free software: you can redistribute it and/or modify it under the * terms of the GNU Affero General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later version. * * Orbital Object ToolKit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License along with * Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>. */ // / Container for cubic spline data. export class CubicSpline { t0; p0; m0; t1; p1; m1; // / Create a new [CubicSpline] object. constructor(t0, p0, m0, t1, p1, m1) { this.t0 = t0; this.p0 = p0; this.m0 = m0; this.t1 = t1; this.p1 = p1; this.m1 = m1; // Nothing to do here. } // / Interpolate position at the provided time [t] _(POSIX seconds)_. position_(t) { const t2 = t * t; const t3 = t2 * t; const r0 = this.p0.scale(2 * t3 - 3 * t2 + 1); const v0 = this.m0.scale((t3 - 2 * t2 + t) * (this.t1 - this.t0)); const r1 = this.p1.scale(-2 * t3 + 3 * t2); const v1 = this.m1.scale((t3 - t2) * (this.t1 - this.t0)); return r0.add(v0).add(r1).add(v1); } // / Interpolate velocity at the provided time [t] _(POSIX seconds)_. velocity_(t) { const t2 = t * t; const r0 = this.p0.scale(6 * t2 - 6 * t); const v0 = this.m0.scale((3 * t2 - 4 * t + 1) * (this.t1 - this.t0)); const r1 = this.p1.scale(-6 * t2 + 6 * t); const v1 = this.m1.scale((3 * t2 - 2 * t) * (this.t1 - this.t0)); return r0 .add(v0) .add(r1) .add(v1) .scale(1 / (this.t1 - this.t0)); } /** * Interpolates the position and velocity at a given time. * (km) and velocity (km/s) vectors at the provided time. * @param t The time value to interpolate at _(POSIX seconds)_. * @returns An array containing the interpolated position and velocity as Vector3D objects. */ interpolate(t) { const n = (t - this.t0) / (this.t1 - this.t0); return [this.position_(n), this.velocity_(n)]; } } //# sourceMappingURL=CubicSpline.js.map