Skip to content

Commit

Permalink
fix: 🐛 fix doppler factor calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 10, 2024
1 parent 6420157 commit fb7d26e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DifferentiableFunction,
JacobianFunction,
Radians,
SpaceObjectType,
} from '../types/types';

/**
Expand Down Expand Up @@ -618,3 +619,38 @@ export function toPrecision(value: number, places: number): number {
export function sign(value: number) {
return value >= 0 ? 1 : -1;
}

const spaceObjTypeStrMap = {
[SpaceObjectType.UNKNOWN]: 'Unknown',
[SpaceObjectType.PAYLOAD]: 'Payload',
[SpaceObjectType.ROCKET_BODY]: 'Rocket Body',
[SpaceObjectType.DEBRIS]: 'Debris',
[SpaceObjectType.SPECIAL]: 'Special',
[SpaceObjectType.BALLISTIC_MISSILE]: 'Ballistic Missile',
[SpaceObjectType.STAR]: 'Star',
[SpaceObjectType.INTERGOVERNMENTAL_ORGANIZATION]: 'Intergovernmental Organization',
[SpaceObjectType.SUBORBITAL_PAYLOAD_OPERATOR]: 'Suborbital Payload Operator',
[SpaceObjectType.PAYLOAD_OWNER]: 'Payload Owner',
[SpaceObjectType.METEOROLOGICAL_ROCKET_LAUNCH_AGENCY_OR_MANUFACTURER]:
'Meteorological Rocket Launch Agency or Manufacturer',
[SpaceObjectType.PAYLOAD_MANUFACTURER]: 'Payload Manufacturer',
[SpaceObjectType.LAUNCH_AGENCY]: 'Launch Agency',
[SpaceObjectType.LAUNCH_SITE]: 'Launch Site',
[SpaceObjectType.LAUNCH_POSITION]: 'Launch Position',
[SpaceObjectType.LAUNCH_FACILITY]: 'Launch Facility',
[SpaceObjectType.CONTROL_FACILITY]: 'Control Facility',
[SpaceObjectType.GROUND_SENSOR_STATION]: 'Ground Sensor Station',
[SpaceObjectType.OPTICAL]: 'Optical',
[SpaceObjectType.MECHANICAL]: 'Mechanical',
[SpaceObjectType.PHASED_ARRAY_RADAR]: 'Phased Array Radar',
[SpaceObjectType.OBSERVER]: 'Observer',
[SpaceObjectType.BISTATIC_RADIO_TELESCOPE]: 'Bi-static Radio Telescope',
[SpaceObjectType.COUNTRY]: 'Country',
[SpaceObjectType.LAUNCH_VEHICLE_MANUFACTURER]: 'Launch Vehicle Manufacturer',
[SpaceObjectType.ENGINE_MANUFACTURER]: 'Engine Manufacturer',
[SpaceObjectType.NOTIONAL]: 'Notional',
[SpaceObjectType.FRAGMENT]: 'Fragment',
};

export const spaceObjType2Str = (spaceObjType: SpaceObjectType): string =>
spaceObjTypeStrMap[spaceObjType] || 'Unknown';
13 changes: 11 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Utils {
return <Kilometers>Math.sqrt((pos1.x - pos2.x) ** 2 + (pos1.y - pos2.y) ** 2 + (pos1.z - pos2.z) ** 2);
}

static dopplerFactor(location: EciVec3, position: EciVec3, velocity: EciVec3): Kilometers {
static dopplerFactor(location: EciVec3, position: EciVec3, velocity: EciVec3): number {
const mfactor = 7.292115e-5;
const c = 299792.458; // Speed of light in km/s

Expand All @@ -60,8 +60,17 @@ class Utils {
};

const rangeRate = (range.x * rangeVel.x + range.y * rangeVel.y + range.z * rangeVel.z) / distance;
let dopplerFactor = 0;

return <Kilometers>(1 + (rangeRate / c) * sign(rangeRate));
if (rangeRate < 0) {
dopplerFactor = 1 + (rangeRate / c) * sign(rangeRate);
}

if (rangeRate >= 0) {
dopplerFactor = 1 - (rangeRate / c) * sign(rangeRate);
}

return dopplerFactor;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Doppler factor', () => {
};
const dopFactor = Utils.dopplerFactor(observerEcf, positionEcf, velocityEcf);

expect(dopFactor).toBeCloseTo(1.0000107847789212, numDigits);
expect(dopFactor).toBeCloseTo(0.9999892152210788, numDigits);
});

test('if negative range rate works', () => {
Expand Down

0 comments on commit fb7d26e

Please sign in to comment.