Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ans 39 #25

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}