Skip to content

Commit

Permalink
Feature/ans 39 (#25)
Browse files Browse the repository at this point in the history
* wcs implemented

* add rotational rate for all COs

* small cleanup

* fix test
  • Loading branch information
ATTron authored Jul 25, 2024
1 parent ce406bd commit fb8c8ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/wcs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/WorldCoordinateSystem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
}
Expand Down Expand Up @@ -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),
Expand All @@ -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);
}

0 comments on commit fb8c8ee

Please sign in to comment.