From b7ff286e921883b16b630c5ee01e762efb74cf12 Mon Sep 17 00:00:00 2001 From: Martin Asprusten Date: Sat, 4 Apr 2026 11:30:18 +0200 Subject: [PATCH] Removed unused stuff so typescript will compile --- src/calculations/orbit-calculations.ts | 136 +------------------------ src/gui/landing.ts | 4 +- src/gui/worker.ts | 2 +- 3 files changed, 4 insertions(+), 138 deletions(-) diff --git a/src/calculations/orbit-calculations.ts b/src/calculations/orbit-calculations.ts index d64315f..0f482c3 100644 --- a/src/calculations/orbit-calculations.ts +++ b/src/calculations/orbit-calculations.ts @@ -1,6 +1,6 @@ import type { InterpolationParameters } from "../gui/interpolate"; import type { Body } from "./constants"; -import { addMatrix, addVector, getVectorMagnitude, invertTwoByTwoMatrix, matrixMultiply, multiplyMatrixWithScalar, normalizeVector, subtractVector, vectorCrossProduct, vectorDotProduct } from "./mathematics"; +import { addVector, getVectorMagnitude, matrixMultiply, multiplyMatrixWithScalar, normalizeVector, subtractVector, vectorCrossProduct, vectorDotProduct } from "./mathematics"; export interface Orbit { semiLatusRectum: number, @@ -1425,8 +1425,6 @@ export function findOrbitThroughInterpolation(ownCoordinates: OrbitalCoordinates const [firstDistanceAlongDirection, firstDistancePerpendicularToDirection] = getDistances(interpolationParameters.firstOwnAltitude, interpolationParameters.firstTargetAltitude, interpolationParameters.firstDistance); const [secondDistanceAlongDirection, secondDistancePerpendicularToDirection] = getDistances(interpolationParameters.secondOwnAltitude, interpolationParameters.secondTargetAltitude, interpolationParameters.secondDistance); - const phaseAngleDifference = (ownSecondTrueAnomaly + interpolationParameters.secondPhaseAngle) - (ownFirstTrueAnomaly + interpolationParameters.firstPhaseAngle); - // Now, try some Newton's method to estimate the two position's the target has gone through // To avoid the maths exploding, we'll scale everything down a bit @@ -1464,138 +1462,6 @@ export function findOrbitThroughInterpolation(ownCoordinates: OrbitalCoordinates return getVectorMagnitude(addVector(p2, multiplyMatrixWithScalar(-1, p1))) - expectedDistance; } - const distancePartialDerivativeAngleOne = (angleOne: number, angleTwo: number) => { - let distance = distanceFunction(angleOne, angleTwo) + expectedDistance; - return ( - Math.sin(angleOne) * vectorDotProduct(n11, c2) - + Math.sin(angleOne) * Math.cos(angleTwo) * vectorDotProduct(n21, n11) - - Math.sin(angleOne) * Math.cos(angleOne) * vectorDotProduct(n11, n11) - - Math.cos(angleOne) * vectorDotProduct(n12, c2) - - Math.cos(angleOne) * Math.sin(angleTwo) * vectorDotProduct(n12, n22) - + Math.sin(angleOne) * Math.sin(angleOne) * vectorDotProduct(n12, n12) - ) / distance; - } - - const distancePartialDerivativeAngleTwo = (angleOne: number, angleTwo: number) => { - let distance = distanceFunction(angleOne, angleTwo) + expectedDistance; - return ( - Math.cos(angleTwo) * Math.sin(angleTwo) * vectorDotProduct(n22, n22) - - Math.cos(angleTwo) * vectorDotProduct(n22, c1) - - Math.cos(angleTwo) * Math.sin(angleOne) * vectorDotProduct(n22, n12) - - Math.sin(angleTwo) * Math.cos(angleTwo) * vectorDotProduct(n21, n21) - + Math.sin(angleTwo) * vectorDotProduct(n21, c1) - + Math.sin(angleTwo) * Math.cos(angleOne) * vectorDotProduct(n21, n11) - ) / distance; - } - - const planeAngleFunction = (angleOne: number, angleTwo: number) => { - const horizontalOne = addVector( - c1, - multiplyMatrixWithScalar(Math.cos(angleOne), n11) - ); - - const horizontalTwo = addVector( - c2, - multiplyMatrixWithScalar(Math.cos(angleTwo), n21) - ); - - return vectorDotProduct(horizontalOne, horizontalTwo) / (getVectorMagnitude(horizontalOne) * getVectorMagnitude(horizontalTwo)) - Math.cos(phaseAngleDifference); - } - - const planeAnglePartialDerivativeAngleOne = (angleOne: number, angleTwo: number) => { - const horizontalOne = addVector( - c1, - multiplyMatrixWithScalar(Math.cos(angleOne), n11) - ); - - const horizontalTwo = addVector( - c2, - multiplyMatrixWithScalar(Math.cos(angleTwo), n21) - ); - - return ( - -Math.sin(angleOne) * vectorDotProduct(n11, c2) - -Math.sin(angleOne) * Math.cos(angleTwo) * vectorDotProduct(n11, n21) - -Math.cos(angleOne) * Math.sin(angleOne) * vectorDotProduct(n11, n11) * vectorDotProduct(horizontalOne, horizontalTwo) / getVectorMagnitude(horizontalOne) - ) / (getVectorMagnitude(horizontalOne) * getVectorMagnitude(horizontalTwo)); - } - - const planeAnglePartialDerivativeAngleTwo = (angleOne: number, angleTwo: number) => { - const horizontalOne = addVector( - c1, - multiplyMatrixWithScalar(Math.cos(angleOne), n11) - ); - - const horizontalTwo = addVector( - c2, - multiplyMatrixWithScalar(Math.cos(angleTwo), n21) - ); - - return ( - -Math.sin(angleTwo) * vectorDotProduct(n21, c1) - -Math.sin(angleTwo) * Math.cos(angleOne) * vectorDotProduct(n21, n11) - -Math.cos(angleTwo) * Math.sin(angleTwo) * vectorDotProduct(n21, n21) * vectorDotProduct(horizontalOne, horizontalTwo) / getVectorMagnitude(horizontalTwo) - ) / (getVectorMagnitude(horizontalOne) * getVectorMagnitude(horizontalTwo)) - } - - // Try to Newton's method up in this bitch - const getFunctionVector = (anglesVector: number[][]) => { - return [ - [distanceFunction(anglesVector[0][0], anglesVector[1][0])], - [planeAngleFunction(anglesVector[0][0], anglesVector[1][0])] - ] - }; - - const getJacobianMatrix = (anglesVector: number[][]) => { - let angleOne = anglesVector[0][0]; - let angleTwo = anglesVector[1][0]; - return[ - [distancePartialDerivativeAngleOne(angleOne, angleTwo), distancePartialDerivativeAngleTwo(angleOne, angleTwo)], - [planeAnglePartialDerivativeAngleOne(angleOne, angleTwo), planeAnglePartialDerivativeAngleTwo(angleOne, angleTwo)] - ] - }; - - const performNewtonMethod = (initialGuess: number[][], iterations: number) => { - let anglesVector = [ - [initialGuess[0][0]], - [initialGuess[1][0]] - ]; - - for (var i = 0; i < iterations; i++) { - let functionVector = getFunctionVector(anglesVector); - let jacobianMatrix = getJacobianMatrix(anglesVector); - - let update = matrixMultiply(invertTwoByTwoMatrix(jacobianMatrix), functionVector); - - // Don't make updates too big - while (getVectorMagnitude(update) > Math.PI / 100) { - update = multiplyMatrixWithScalar(0.5, update); - } - /** - // Also don't update if it brings us further away from where we want to be - let trialFunctionVector = getFunctionVector(addVector(anglesVector, multiplyMatrixWithScalar(-1, update))); - let counter = 0; - let deadEnd = false; - - while (Math.abs(trialFunctionVector[0][0]) >= Math.abs(functionVector[0][0])) { - counter += 1; - if (counter >= 16) { - deadEnd = true; - break; - } - - update = multiplyMatrixWithScalar(0.5, update); - trialFunctionVector = getFunctionVector(addVector(anglesVector, multiplyMatrixWithScalar(-1, update))); - } - - if (deadEnd) { - break; - }*/ - anglesVector = addVector(anglesVector, multiplyMatrixWithScalar(-1, update)); - }; - return anglesVector; - } - const getAnglesFromPhaseAngles = (firstPhaseAngle: number, secondPhaseAngle: number) => { let angleOne; let angleTwo; diff --git a/src/gui/landing.ts b/src/gui/landing.ts index ff5290c..650483e 100644 --- a/src/gui/landing.ts +++ b/src/gui/landing.ts @@ -1,7 +1,7 @@ import type { Body } from "../calculations/constants"; -import { extrapolateTrajectory, findCheapestLanding, getOrbitalCoordinates, type OrbitalCoordinates, type ShipParameters } from "../calculations/orbit-calculations"; +import { extrapolateTrajectory, type OrbitalCoordinates, type ShipParameters } from "../calculations/orbit-calculations"; import type { ChangingStorageValue } from "../storage"; -import { createDisabledInput, createLabel, getCoordinatesFromParameters, getOrbitFromParameters, type OrbitalParameters } from "./common"; +import { createDisabledInput, createLabel, getCoordinatesFromParameters, type OrbitalParameters } from "./common"; import { type LandingParameters } from "../calculations/orbit-calculations"; import { LandingParametersGui } from "./landingparameters"; import { ShipGui } from "./ship"; diff --git a/src/gui/worker.ts b/src/gui/worker.ts index aad183e..028fc14 100644 --- a/src/gui/worker.ts +++ b/src/gui/worker.ts @@ -1,6 +1,6 @@ import type { Body } from "../calculations/constants"; import { findCheapestIntercept, findCheapestLanding, findCheapestTransfer, type Orbit, type OrbitalCoordinates, type ShipParameters, type Transfer } from "../calculations/orbit-calculations"; -import type { Landing, LandingParameters, LandingProgressCallbackFunction, Manoeuvre } from "../calculations/orbit-calculations"; +import type { Landing, LandingParameters, LandingProgressCallbackFunction } from "../calculations/orbit-calculations"; const ctx: Worker = self as any;