Skip to content

Commit

Permalink
feat: 🚚 move rf math to ootk
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent 56ce400 commit f174259
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 281 deletions.
3 changes: 2 additions & 1 deletion src/interfaces/SensorParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Degrees, Kilometers, SpaceObjectType } from '../types/types';
import { BaseObjectParams } from './BaseObjectParams';

export interface SensorParams {
export interface SensorParams extends BaseObjectParams{
/** Altitude in Kilometers */
alt: Kilometers;
/** Latitude in Degrees */
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type { GroundPositionParams } from './GroundPositionParams';
export type { OptionsParams } from './OptionsParams';
export type { SatelliteParams } from './SatelliteParams';
export type { SensorParams } from './SensorParams';
export type { RfSensorParams } from './RfSensorParams';

Check failure on line 6 in src/interfaces/index.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './RfSensorParams' or its corresponding type declarations.
export type { StarObjectParams } from './StarObjectParams';
export type { ClassicalElementsParams } from './ClassicalElementsParams';
export type { EquinoctialElementsParams } from './EquinoctialElementsParams';
35 changes: 0 additions & 35 deletions src/objects/RadarSensor.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

export { BaseObject } from './BaseObject';
export type { RadarSensor } from './RadarSensor';
export { GroundObject } from './GroundObject';
export { Satellite } from './Satellite';
export { Sensor } from './Sensor';
Expand Down
117 changes: 0 additions & 117 deletions src/transforms/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,15 @@ import {
MILLISECONDS_TO_DAYS,
PI,
RAD2DEG,
RadarSensor,
Radians,
RaeVec3,
RfVec3,
RuvVec3,
Sensor,
SezVec3,
Sgp4,
TAU,
} from '../main';
import { TransformCache } from './TransformCache';

/**
* Converts Azimuth and Elevation to U and V.
* Azimuth is the angle off of boresight in the horizontal plane.
* Elevation is the angle off of boresight in the vertical plane.
* Cone half angle is the angle of the cone of the radar max field of view.
* @param az - Azimuth in radians
* @param el - Elevation in radians
* @param coneHalfAngle - Cone half angle in radians
* @returns U and V in radians
*/
export function azel2uv(az: Radians, el: Radians, coneHalfAngle: Radians): { u: Radians; v: Radians } {
if (az > coneHalfAngle && az < coneHalfAngle) {
throw new RangeError(`Azimuth is out of bounds: ${az}`);
}

if (el > coneHalfAngle && el < coneHalfAngle) {
throw new RangeError(`Elevation is out of bounds: ${el}`);
}

const alpha = (az / (coneHalfAngle * RAD2DEG)) * 90;
const beta = (el / (coneHalfAngle * RAD2DEG)) * 90;

const u = Math.sin(alpha) as Radians;
let v = -Math.sin(beta) as Radians;

v = Object.is(v, -0) ? (0 as Radians) : v;

return { u, v };
}

/**
* Converts ECF to ECI coordinates.
*
Expand Down Expand Up @@ -192,28 +159,6 @@ export function eci2lla(eci: EciVec3, gmst: number): LlaVec3<Degrees, Kilometers
return lla;
}

/**
* Converts coordinates from East-North-Up (ENU) to Right-Front-Up (RF) coordinate system.
* @param enu - The ENU coordinates to be converted.
* @param enu.x - The east coordinate.
* @param enu.y - The north coordinate.
* @param enu.z - The up coordinate.
* @param az - The azimuth angle in radians.
* @param el - The elevation angle in radians.
* @returns The converted RF coordinates.
*/
export function enu2rf<D extends number, A extends number = Radians>({ x, y, z }: EnuVec3<D>, az: A, el: A): RfVec3<D> {
const xrf = Math.cos(el) * Math.cos(az) * x - Math.sin(az) * y + Math.sin(el) * Math.cos(az) * z;
const yrf = Math.cos(el) * Math.sin(az) * x + Math.cos(az) * y + Math.sin(el) * Math.sin(az) * z;
const zrf = -Math.sin(el) * x + Math.cos(el) * z;

return {
x: xrf as D,
y: yrf as D,
z: zrf as D,
};
}

/**
* Converts geodetic coordinates (longitude, latitude, altitude) to Earth-Centered Earth-Fixed (ECF) coordinates.
* @param lla The geodetic coordinates in radians and meters.
Expand Down Expand Up @@ -437,44 +382,6 @@ export function rae2enu(rae: RaeVec3): EnuVec3<Kilometers> {
return { x: e, y: n, z: u };
}

/**
* Determine azimuth and elevation off of boresight based on sensor orientation and RAE.
* @param rae Range, Azimuth, Elevation
* @param sensor Radar sensor object
* @param maxSensorAz Maximum sensor azimuth
* @returns Azimuth and Elevation off of boresight
*/
export function rae2raeOffBoresight(
rae: RaeVec3,
sensor: RadarSensor,
maxSensorAz: Degrees,
): { az: Radians; el: Radians } {
let az = (rae.az * DEG2RAD) as Radians;
let el = (rae.el * DEG2RAD) as Radians;

// Correct azimuth for sensor orientation.
az = az > maxSensorAz * DEG2RAD ? ((az - TAU) as Radians) : az;

az = (az - sensor.boresight.az) as Radians;
el = (el - sensor.boresight.el) as Radians;

return { az, el };
}

/**
* Converts Range Az El to Range U V.
* @param rae Range, Azimuth, Elevation
* @param sensor Radar sensor object
* @param maxSensorAz Maximum sensor azimuth
* @returns Range, U, V
*/
export function rae2ruv(rae: RaeVec3, sensor: RadarSensor, maxSensorAz: Degrees): RuvVec3 {
const { az, el } = rae2raeOffBoresight(rae, sensor, maxSensorAz);
const { u, v } = azel2uv(az, el, sensor.coneHalfAngle);

return { rng: rae.rng, u, v };
}

/**
* Converts South, East, and Zenith (SEZ) coordinates to Right Ascension, Elevation, and Range (RAE) coordinates.
* @param sez The SEZ coordinates.
Expand All @@ -488,30 +395,6 @@ export function sez2rae<D extends number>(sez: SezVec3<D>): RaeVec3<D, Radians>
return { rng, az, el };
}

/**
* Converts U and V to Azimuth and Elevation off of boresight.
* @param u The U coordinate.
* @param v The V coordinate.
* @param coneHalfAngle The cone half angle of the radar.
* @returns Azimuth and Elevation off of boresight.
*/
export function uv2azel(u: Radians, v: Radians, coneHalfAngle: Radians): { az: Radians; el: Radians } {
if (u > 1 || u < -1) {
throw new RangeError(`u is out of bounds: ${u}`);
}

if (v > 1 || v < -1) {
throw new RangeError(`v is out of bounds: ${v}`);
}

const alpha = Math.asin(u) as Radians;
const beta = Math.asin(v) as Radians;
const az = ((alpha / 90) * (coneHalfAngle * RAD2DEG)) as Radians;
const el = ((beta / 90) * (coneHalfAngle * RAD2DEG)) as Radians;

return { az, el };
}

/**
* Converts Earth-Centered Fixed (ECF) coordinates to Right Ascension (RA),
* Elevation (E), and Azimuth (A) coordinates.
Expand Down
32 changes: 0 additions & 32 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,38 +428,6 @@ export type PosVel<T> = {
velocity: Vec3<T>;
};

/**
* The RUV coordinate system is a spherical coordinate system with the origin at
* the radar. The RUV coordinate system is defined with respect to the radar
* boresight. The R-axis points outward along the boresight with the origin at
* the radar. The U-axis is in the horizontal plane and points to the right of
* the boresight. The V-axis is in the vertical plane and points down from the
* boresight.
* @template DistanceUnit The unit of measure used for the altitude dimension.
* This is typically a type representing a distance, such as kilometers or
* meters. The default is Kilometers.
* @template AngleUnit The unit of measure used for the latitude and longitude
* dimensions. This is typically a type representing an angle, such as degrees
* or radians. The default is Radians.
*/
export type RuvVec3<DistanceUnit = Kilometers, AngleUnit = Radians> = {
rng: DistanceUnit;
u: AngleUnit;
v: AngleUnit;
};

/**
* Phased Array Radar Face Cartesian Coordinates The cartesian coordinates (XRF,
* YRF ZRF) are defined with respect to the phased array radar face. The radar
* face lies in the XRF-YRF plane, with the XRF-axis horizontal and the YRF-axis
* pointing upward. The ZRF-axis points outward along the normal to the array
* face.
*
* The orientation of the phased array face is defined by the azimuth and the
* elevation of the phased array boresight (i.e., the phased array Z-axis).
*/
export type RfVec3<Units = Kilometers> = Vec3<Units>;

/**
* A type that represents a three-dimensional vector in a flat array format.
* This type is used in vector mathematics and physics calculations.
Expand Down
23 changes: 0 additions & 23 deletions test/transforms/__snapshots__/transforms.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,3 @@ Object {
"z": 0,
}
`;

exports[`Rae2Ecf should convert valid RAE coordinates to RAE Off Boresight 1`] = `
Object {
"az": 0,
"el": 0,
}
`;

exports[`Rae2Ecf should convert valid RAE coordinates to RUV 1`] = `
Object {
"x": 0,
"y": 0,
"z": 0,
}
`;

exports[`Rae2Ecf should convert valid azimuth and elevation to unit vector 1`] = `0`;

exports[`Rae2Ecf should convert valid azimuth and elevation to unit vector 2`] = `0`;

exports[`Rae2Ecf should convert valid unit vector to azimuth and elevation 1`] = `0`;

exports[`Rae2Ecf should convert valid unit vector to azimuth and elevation 2`] = `0`;
74 changes: 2 additions & 72 deletions test/transforms/transforms.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
RadarSensor,
azel2uv,
DEG2RAD,
Degrees,
ecf2eci,
ecf2enu,
Expand All @@ -17,10 +14,8 @@ import {
Radians,
rae2ecf,
rae2enu,
rae2raeOffBoresight,
rae2sez,
Sensor,
uv2azel,
eci2rae,
Vec3,
lla2eci,
Expand Down Expand Up @@ -165,17 +160,6 @@ describe('Rae2Ecf', () => {
expect(ecfCoordinates.z).toBeCloseTo(ecf.z);
});

// azel2uv
it('should convert valid azimuth and elevation to unit vector', () => {
const az = 0 as Radians;
const el = 0 as Radians;

const uvCoordinates = azel2uv(az, el, (5 * DEG2RAD) as Radians);

expect(uvCoordinates.u).toMatchSnapshot();
expect(uvCoordinates.v).toMatchSnapshot();
});

// ecf2enu
it('should convert valid ECF coordinates to ENU', () => {
const ecf = {
Expand Down Expand Up @@ -255,7 +239,7 @@ describe('Rae2Ecf', () => {
maxEl: 0 as Degrees,
minRng: 0 as Kilometers,
maxRng: 0 as Kilometers,
}) as RadarSensor;
}) as Sensor;
const exampleDate = new Date(1705109326817);
const { gmst } = calcGmst(exampleDate);

Expand All @@ -276,60 +260,6 @@ describe('Rae2Ecf', () => {
expect(enuCoordinates).toMatchSnapshot();
});

// rae2raeOffBoresight
it('should convert valid RAE coordinates to RAE Off Boresight', () => {
const rae = {
rng: 0 as Kilometers,
az: 0 as Degrees,
el: 0 as Degrees,
};

const senor = new Sensor({
lat: 0 as Degrees,
lon: 0 as Degrees,
alt: 0 as Kilometers,
minAz: 0 as Degrees,
maxAz: 0 as Degrees,
minEl: 0 as Degrees,
maxEl: 0 as Degrees,
minRng: 0 as Kilometers,
maxRng: 0 as Kilometers,
}) as RadarSensor;

senor.boresight = {
az: 0 as Radians,
el: 0 as Radians,
};
senor.coneHalfAngle = 0 as Radians;

const raeOffBoresightCoordinates = rae2raeOffBoresight(rae, senor, 10 as Degrees);

expect(raeOffBoresightCoordinates).toMatchSnapshot();
});

// rae2ruv
it('should convert valid RAE coordinates to RUV', () => {
const rae = {
rng: 0 as Kilometers,
az: 0 as Degrees,
el: 0 as Degrees,
};
const ruvCoordinates = rae2enu(rae);

expect(ruvCoordinates).toMatchSnapshot();
});

// uv2azel
it('should convert valid unit vector to azimuth and elevation', () => {
const u = 0 as Radians;
const v = 0 as Radians;

const azelCoordinates = uv2azel(u, v, (5 * DEG2RAD) as Radians);

expect(azelCoordinates.az).toMatchSnapshot();
expect(azelCoordinates.el).toMatchSnapshot();
});

// eci2rae
it('should convert valid ECI coordinates to RAE', () => {
const eci = {
Expand All @@ -347,7 +277,7 @@ describe('Rae2Ecf', () => {
maxEl: 0 as Degrees,
minRng: 0 as Kilometers,
maxRng: 0 as Kilometers,
}) as RadarSensor;
}) as Sensor;

const exampleDate = new Date(1705109326817);
const raeCoordinates = eci2rae(exampleDate, eci, sensor);
Expand Down

0 comments on commit f174259

Please sign in to comment.