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.

263 lines (262 loc) 9.79 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. */ import { Vector3D, Matrix, Degrees, Radians } from '../main.js'; /** * A Vector is a mathematical object that has both magnitude and direction. */ export declare class Vector<T extends number = number> { elements: T[] | Float64Array; /** * The length of the vector. */ readonly length: number; /** * Represents a 3-dimensional vector. */ static readonly origin3: Vector<0>; /** * Represents a vector with all elements set to zero. */ static readonly origin6: Vector<0>; /** * Represents the x-axis vector. */ static readonly xAxis: Vector<0 | 1>; /** * Represents the y-axis vector. */ static readonly yAxis: Vector<0 | 1>; /** * Represents the z-axis vector. */ static readonly zAxis: Vector<0 | 1>; /** * Represents a vector pointing along the negative x-axis. */ static readonly xAxisNeg: Vector<0 | -1>; /** * Represents a vector pointing along the negative y-axis. */ static readonly yAxisNeg: Vector<0 | -1>; /** * Represents a vector pointing along the negative z-axis. */ static readonly zAxisNeg: Vector<0 | -1>; constructor(elements: T[] | Float64Array); /** * Creates a zero vector of the specified length. * @param length The length of the vector. * @returns A new Vector object representing the zero vector. */ static zero(length: number): Vector; /** * Creates a new Vector with the specified length, filled with the specified * value. * @param length The length of the new Vector. * @param value The value to fill the Vector with. * @returns A new Vector filled with the specified value. */ static filled(length: number, value: number): Vector; /** * Creates a new Vector instance from an array of elements. * @param elements - The array of elements to create the Vector from. * @returns A new Vector instance. */ static fromList(elements: number[]): Vector; /** * Returns a string representation of the vector. * @param fixed - The number of digits to appear after the decimal point. * Defaults to -1. * @returns A string representation of the vector. */ toString(fixed?: number): string; /** * Returns a string representation of the x value of the vector. * @returns A string representation of the x value of the vector. */ get x(): number; /** * Returns a string representation of the y value of the vector. * @returns A string representation of the y value of the vector. */ get y(): number; /** * Returns a string representation of the z value of the vector. * @returns A string representation of the z value of the vector. */ get z(): number; /** * Converts the vector elements to an array. * @returns An array containing the vector elements. */ toList(): number[]; /** * Converts the vector to a Float64Array. * @returns The vector as a Float64Array. */ toArray(): Float64Array; /** * Calculates the magnitude of the vector. * @returns The magnitude of the vector. */ magnitude(): number; /** * Adds the elements of another vector to this vector and returns a new * vector. * @param v - The vector to add. * @returns A new vector containing the sum of the elements. */ add(v: Vector): Vector; /** * Subtracts a vector from the current vector. * @param v The vector to subtract. * @returns A new vector representing the result of the subtraction. */ subtract(v: Vector): Vector; /** * Scales the vector by a given factor. * @param n The scaling factor. * @returns A new Vector object representing the scaled vector. */ scale(n: number): Vector; /** * Negates the vector by scaling it by -1. * @returns A new Vector object representing the negated vector. */ negate(): Vector; /** * Return the Euclidean distance between this and another Vector. * @param v The vector to calculate the distance to. * @returns The distance between the two vectors. */ distance(v: Vector): number; /** * Normalizes the vector, making it a unit vector with the same direction but * a magnitude of 1. If the vector has a magnitude of 0, it returns a zero * vector of the same length. * @returns The normalized vector. */ normalize(): Vector; /** * Calculates the dot product of this vector and another vector. * @param v - The vector to calculate the dot product with. * @returns The dot product of the two vectors. */ dot(v: Vector): number; /** * Calculates the outer product of this vector with another vector. * @param v The vector to calculate the outer product with. * @returns A matrix representing the outer product of the two vectors. */ outer(v: Vector): Matrix; /** * Calculates the cross product of this vector and the given vector. * @param v - The vector to calculate the cross product with. * @returns The resulting vector. */ cross(v: Vector): Vector; /** * Calculate the skew-symmetric matrix for this [Vector]. * @returns The skew-symmetric matrix. * @throws [Error] if the vector is not of length 3. */ skewSymmetric(): Matrix; /** * Rotates the vector around the X-axis by the specified angle. * @param theta The angle in radians. * @returns The rotated vector. */ rotX(theta: Radians): Vector; /** * Rotates the vector around the Y-axis by the specified angle. * @param theta The angle of rotation in radians. * @returns A new Vector representing the rotated vector. */ rotY(theta: Radians): Vector; /** * Rotates the vector around the Z-axis by the specified angle. * @param theta The angle of rotation in radians. * @returns A new Vector representing the rotated vector. */ rotZ(theta: Radians): Vector; /** * Calculates the angle between this vector and another vector. * @param v The other vector. * @returns The angle between the two vectors in radians. */ angle(v: Vector): Radians; /** * Calculates the angle between this vector and another vector in degrees. * @param v The other vector. * @returns The angle between the two vectors in degrees. */ angleDegrees(v: Vector): Degrees; /** * Determines if there is line of sight between this vector and another vector * within a given radius. * @param v - The vector to check line of sight with. * @param radius - The radius within which line of sight is considered. * @returns True if there is line of sight, false otherwise. */ sight(v: Vector, radius: number): boolean; /** * Returns the bisect vector between this vector and the given vector. The * bisect vector is calculated by scaling this vector's magnitude by the * magnitude of the given vector, adding the result to the product of scaling * the given vector's magnitude by this vector's magnitude, and then * normalizing the resulting vector. * @param v - The vector to calculate the bisect with. * @returns The bisect vector. */ bisect(v: Vector): Vector; /** * Joins the current vector with another vector. * @param v The vector to join with. * @returns A new vector that contains the elements of both vectors. */ join(v: Vector): Vector; /** * Returns a new Vector containing a portion of the elements from the * specified start index to the specified end index * @param start The start index of the slice (inclusive). * @param end The end index of the slice (exclusive). * @returns A new Vector containing the sliced elements. */ slice(start: number, end: number): Vector; /** * Returns a new Matrix object representing the row vector. * @returns The row vector as a Matrix object. */ row(): Matrix; /** * Returns a new Matrix object representing the column vector of this Vector. * @returns The column vector as a Matrix object. */ column(): Matrix; /** * Converts the elements at the specified index to a Vector3D object. * @param index - The index of the elements to convert. * @returns A new Vector3D object containing the converted elements. */ toVector3D(index: number): Vector3D; }