From f77390ce1d6c5ee4ee3ce6344c85a6fba3329814 Mon Sep 17 00:00:00 2001 From: Theodore Kruczek Date: Sun, 14 Jan 2024 16:48:03 -0500 Subject: [PATCH] test: :white_check_mark: add tests for J2000 --- src/coordinate/J2000.ts | 26 ++++++++++++- test/coordinate/J2000.test.ts | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/coordinate/J2000.test.ts diff --git a/src/coordinate/J2000.ts b/src/coordinate/J2000.ts index f7af5e6..2792025 100644 --- a/src/coordinate/J2000.ts +++ b/src/coordinate/J2000.ts @@ -5,9 +5,23 @@ import { ITRF } from './ITRF'; import { StateVector } from './StateVector'; import { TEME } from './TEME'; +/** + * Represents a position and velocity in the J2000 coordinate system. This is an + * Earth-centered inertial (ECI) coordinate system. + * + * Commonly used ECI frame is defined with the Earth's Mean Equator and Mean + * Equinox (MEME) at 12:00 Terrestrial Time on 1 January 2000. It can be + * referred to as J2K, J2000 or EME2000. The x-axis is aligned with the mean + * vernal equinox. The z-axis is aligned with the Earth's rotation axis (or + * equivalently, the celestial North Pole) as it was at that time. The y-axis is + * rotated by 90° East about the celestial equator. + * + * @see https://en.wikipedia.org/wiki/Earth-centered_inertial + */ export class J2000 extends StateVector { /** - * Creates a J2000 instance from classical elements. + * Creates a J2000 coordinate from classical elements. + * @param elements The classical elements. @returns The J2000 coordinate. */ static fromClassicalElements(elements: ClassicalElements): J2000 { const rv = elements.toPositionVelocity(); @@ -17,6 +31,7 @@ export class J2000 extends StateVector { /** * Gets the name of the coordinate system. + * @returns The name of the coordinate system. */ get name(): string { return 'J2000'; @@ -24,6 +39,8 @@ export class J2000 extends StateVector { /** * Gets a value indicating whether the coordinate system is inertial. + * @returns A boolean value indicating whether the coordinate system is + * inertial. */ get inertial(): boolean { return true; @@ -34,6 +51,8 @@ export class J2000 extends StateVector { * Reference Frame (ITRF). * * This is an ECI to ECF transformation. + * + * @returns The ITRF coordinates. */ toITRF(): ITRF { const p = Earth.precession(this.epoch); @@ -49,6 +68,11 @@ export class J2000 extends StateVector { return new ITRF(this.epoch, rPEF, vPEF); } + /** + * Converts the J2000 coordinate to the TEME coordinate. + * + * @returns The TEME coordinate. + */ toTEME(): TEME { const p = Earth.precession(this.epoch); const n = Earth.nutation(this.epoch); diff --git a/test/coordinate/J2000.test.ts b/test/coordinate/J2000.test.ts new file mode 100644 index 0000000..560710a --- /dev/null +++ b/test/coordinate/J2000.test.ts @@ -0,0 +1,70 @@ +// Generated by CodiumAI + +import { EpochUTC, ClassicalElements, Kilometers, Radians, J2000, Vector3D } from '../../src/main'; +import { exampleDate } from '../lib/mockData'; + +describe('J2000', () => { + const epoch = EpochUTC.fromDateTime(exampleDate); + + // can be created from classical elements + it('should create a J2000 coordinate from classical elements', () => { + const elements = new ClassicalElements({ + epoch, + semimajorAxis: 6943.547853722985 as Kilometers, + eccentricity: 0.0011235968124658146, + inclination: 0.7509087232045765 as Radians, + rightAscension: 0.028239555738616327 as Radians, + argPerigee: 2.5386411901807353 as Radians, + trueAnomaly: 0.5931399364974058 as Radians, + }); + const j2000 = J2000.fromClassicalElements(elements); + + expect(j2000.epoch).toEqual(elements.epoch); + expect(j2000.position).toEqual(elements.toPositionVelocity().position); + expect(j2000.velocity).toEqual(elements.toPositionVelocity().velocity); + }); + + // can get the name of the coordinate system + it('should return the name of the coordinate system as "J2000"', () => { + const j2000 = new J2000( + epoch, + new Vector3D(5000 as Kilometers, 10000 as Kilometers, 2100 as Kilometers), + new Vector3D(7 as Kilometers, 4 as Kilometers, 2 as Kilometers), + ); + + expect(j2000.name).toBe('J2000'); + }); + + // can get a value indicating whether the coordinate system is inertial + it('should return true for the inertial property', () => { + const j2000 = new J2000( + epoch, + new Vector3D(5000 as Kilometers, 10000 as Kilometers, 2100 as Kilometers), + new Vector3D(7 as Kilometers, 4 as Kilometers, 2 as Kilometers), + ); + + expect(j2000.inertial).toBe(true); + }); + + // Check conversion to and from + it('should convert to and from other coordinate systems', () => { + const j2000 = new J2000( + epoch, + new Vector3D(5000 as Kilometers, 10000 as Kilometers, 2100 as Kilometers), + new Vector3D(7 as Kilometers, 4 as Kilometers, 2 as Kilometers), + ); + const itrf = j2000.toITRF(); + const j200FromItf = itrf.toJ2000(); + + expect(j200FromItf.position.x).toBeCloseTo(j2000.position.x, 8); + expect(j200FromItf.position.y).toBeCloseTo(j2000.position.y, 8); + expect(j200FromItf.position.z).toBeCloseTo(j2000.position.z, 8); + + const teme = j2000.toTEME(); + const j200FromTeme = teme.toJ2000(); + + expect(j200FromTeme.position.x).toBeCloseTo(j2000.position.x, 8); + expect(j200FromTeme.position.y).toBeCloseTo(j2000.position.y, 8); + expect(j200FromTeme.position.z).toBeCloseTo(j2000.position.z, 8); + }); +});