From fb8c8ee43b2b11eb84910ae85d684d8249b3434c Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Thu, 25 Jul 2024 03:55:47 -0400 Subject: [PATCH] Feature/ans 39 (#25) * wcs implemented * add rotational rate for all COs * small cleanup * fix test --- examples/wcs.zig | 2 +- src/WorldCoordinateSystem.zig | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/wcs.zig b/examples/wcs.zig index 34de86b..f307927 100644 --- a/examples/wcs.zig +++ b/examples/wcs.zig @@ -15,7 +15,7 @@ pub fn main() !void { var tle = try Tle.parse(test_tle, allocator); defer tle.deinit(); - const wcs = WorldCoordinateSystem.fromTle(test_tle, 0.0); + const wcs = WorldCoordinateSystem.fromTle(test_tle, 0.0, astroz.constants.earth); std.log.debug("WCS OUTPUT: {any}", wcs); diff --git a/src/WorldCoordinateSystem.zig b/src/WorldCoordinateSystem.zig index a3cb14d..2a879c5 100644 --- a/src/WorldCoordinateSystem.zig +++ b/src/WorldCoordinateSystem.zig @@ -16,12 +16,12 @@ y: f64, z: f64, /// Currently this function assumes a fully parsed TLE already -pub fn fromTle(tle: Tle, t0: f64) WorldCoordinateSystem { +pub fn fromTle(tle: Tle, t0: f64, celestial_object: constants.CelestialBody) WorldCoordinateSystem { std.log.info("TLE PARSING, {}", .{tle}); const orbital_elements = calculations.tleToOrbitalElements(tle); const eci = orbitalElementsToECI(orbital_elements); - const ecef = eciToECEF(eci, t0); + const ecef = eciToECEF(eci, t0, celestial_object); return .{ .x = ecef[0], .y = ecef[1], .z = ecef[2] }; } @@ -58,8 +58,8 @@ fn orbitalElementsToECI(elements: Spacecraft.OrbitalElements) Vector3 { }; } -fn eciToECEF(eci: Vector3, time_since_epoch: f64) Vector3 { - const m = constants.earth.rotation_rate * time_since_epoch; +fn eciToECEF(eci: Vector3, time_since_epoch: f64, celestial_object: constants.CelestialBody) Vector3 { + const m = celestial_object.rotation_rate * time_since_epoch; return .{ eci[0] * @cos(m) + eci[1] * @sin(m), -eci[0] * @sin(m) + eci[1] * @cos(m), @@ -76,7 +76,7 @@ test WorldCoordinateSystem { var test_tle = try Tle.parse(raw_tle, std.testing.allocator); defer test_tle.deinit(); - const wcs = WorldCoordinateSystem.fromTle(test_tle, 0.0); + const wcs = WorldCoordinateSystem.fromTle(test_tle, 0.0, constants.earth); try std.testing.expectEqualDeep(expected_ecs, wcs); }