keplerian-core
Version:
High-performance TypeScript library for orbital mechanics calculations, providing numerical integration, state propagation, and perturbation modeling for Keplerian orbits.
60 lines (59 loc) • 3.38 kB
JavaScript
/**
* Checks if the spacecraft is at apoapsis (farthest point from central body) in a 2D elliptical orbit.
* For a 2D orbit, apoapsis occurs when the velocity vector is perpendicular to the position vector
* and the distance is at a local maximum.
* @param state The current orbital state (position and velocity).
* @returns True if at apoapsis, false otherwise.
*/
export function isApoapsis2D(state) {
// In a 2D elliptical orbit, apoapsis/periapsis occurs when position and velocity vectors are orthogonal.
// This means their dot product is zero.
// We also need to check if the distance is increasing or decreasing to distinguish apoapsis from periapsis.
// For simplicity, this function will just check orthogonality.
const dotProduct = state.position.x * state.velocity.x + state.position.y * state.velocity.y;
// Check if dot product is close to zero (within a small epsilon)
return Math.abs(dotProduct) < 1e-6;
}
/**
* Checks if the spacecraft is at periapsis (closest point to central body) in a 2D elliptical orbit.
* Similar to apoapsis, periapsis occurs when velocity is perpendicular to position.
* @param state The current orbital state (position and velocity).
* @returns True if at periapsis, false otherwise.
*/
export function isPeriapsis2D(state) {
// Same condition as apoapsis for 2D orthogonality.
// In a full 3D/orbital elements context, one would compare current distance to semi-major axis
// or check the sign of the radial velocity component.
const dotProduct = state.position.x * state.velocity.x + state.position.y * state.velocity.y;
return Math.abs(dotProduct) < 1e-6;
}
/**
* Placeholder for ground track event detection (e.g., crossing a specific longitude).
* This would require ECEF coordinates and knowledge of Earth's rotation.
* @param ecefPosition The spacecraft's position in Earth-Centered, Earth-Fixed coordinates.
* @param targetLongitude The longitude to detect crossing.
* @returns True if crossing the target longitude, false otherwise.
*/
export function isCrossingLongitude(ecefPosition, targetLongitude) {
// This is a conceptual placeholder. In a 2D simulation, ECEF is simplified.
// For a real implementation, you'd calculate the current longitude from ecefPosition
// and compare it to the targetLongitude, considering direction of travel.
console.warn('isCrossingLongitude is a placeholder and requires full 3D ECEF conversion.');
return false; // Always false for now as it's a placeholder
}
/**
* Placeholder for eclipse detection.
* This would require positions of the Sun, Earth, and spacecraft, and their radii.
* @param scPosition The spacecraft's position.
* @param sunPosition The Sun's position.
* @param earthPosition The Earth's position.
* @param earthRadius The radius of the Earth.
* @param sunRadius The radius of the Sun.
* @returns True if in eclipse, false otherwise.
*/
export function isInEclipse(scPosition, sunPosition, earthPosition, earthRadius, sunRadius) {
// This is a conceptual placeholder. Eclipse detection is a complex 3D geometry problem.
// It involves checking if the spacecraft is in the umbra or penumbra of the Earth's shadow.
console.warn('isInEclipse is a placeholder and requires full 3D geometry calculations.');
return false; // Always false for now as it's a placeholder
}