Skip to content

Commit

Permalink
Merge pull request #6 from ATTron/feature/sc-68
Browse files Browse the repository at this point in the history
feat: [sc-68] Astroz: add planetary constants
  • Loading branch information
ATTron authored Jun 29, 2024
2 parents 4071e1f + cd0b182 commit 97c8f2f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ pub fn build(b: *std.Build) void {

const run_time_unit_tests = b.addRunArtifact(time_unit_tests);

const constants_unit_tests = b.addTest(.{
.root_source_file = b.path("src/constants.zig"),
});

const run_constants_unit_tests = b.addRunArtifact(constants_unit_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_coord_unit_tests.step);
test_step.dependOn(&run_ccsds_unit_tests.step);
test_step.dependOn(&run_time_unit_tests.step);
test_step.dependOn(&run_constants_unit_tests.step);
}
54 changes: 54 additions & 0 deletions src/constants.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const std = @import("std");
const math = std.math;
// gravity
pub const G = 6.6743e-11;
// sol
Expand All @@ -12,3 +14,55 @@ pub const h = 6.62607015e-34;
pub const au = 1.49597871e+11;
// Year 2000
pub const j2k = 2000.0;

const Celestial_Body = struct {
mass: f64, // kg
mu: f64, // km^3/s^2
m_fraction_solar_system: f64,
m_radius: ?f64, //km
eq_radius: ?f64, //km
p_radius: ?f64, //km
semi_major_axis: f64, // km
perihelion: f64, // km
aphelion: f64, // km
period: f64, // days
velocity: f64, // km/s
eccentricity: f64,
inclination: f64, // degrees

const Self = @This();

fn new(mass: f64, mu: f64, m_fraction_solar_system: f64, m_radius: ?f64, eq_radius: ?f64, p_radius: ?f64, semi_major_axis: ?f64, perihelion: ?f64, aphelion: ?f64, period: ?f64, velocity: ?f64, eccentricity: ?f64, inclination: ?f64) Self {
return .{
.mass = mass,
.mu = mu,
.m_fraction_solar_system = m_fraction_solar_system,
.m_radius = m_radius orelse null,
.eq_radius = eq_radius orelse null,
.p_radius = p_radius,
.semi_major_axis = semi_major_axis orelse 0.0,
.perihelion = perihelion orelse 0.0,
.aphelion = aphelion orelse 0.0,
.period = period orelse 0.0,
.velocity = velocity orelse 0.0,
.eccentricity = eccentricity orelse 0.0,
.inclination = inclination orelse 0.0,
};
}
};

pub const sun = Celestial_Body.new(1.8842e30, 1.32712e11, 9.98657e-1, null, 695700, null, null, null, null, null, null, null, null);
pub const mercury = Celestial_Body.new(3.30101e23, 2.20319e4, 1.65789e-7, 2439.4, 2440.53, 2438.26, 5.79091e7, 4.60009e7, 6.98173e7, 87.97, 47.87, 0.20564, 7.01);
pub const venus = Celestial_Body.new(4.86732e24, 3.24859e5, 2.44455e-6, 6051.8, 6051.8, 6051.8, 1.08209e8, 1.07477e8, 1.08940e8, 224.70, 35.02, 0.00676, 3.39);
pub const earth = Celestial_Body.new(5.97219e24, 3.98600e5, 2.99946e-6, 6371.0084, 6378.1366, 6356.7519, 1.49598e8, 1.47100e8, 1.52096e8, 365.26, 29.78, 0.01670, 0.00);
pub const moon = Celestial_Body.new(7.34581e22, 4.90280e3, 3.68934e-8, 1737.4, null, null, 3.83398e5, 3.62106e5, 4.04689e5, 27.18, 1.03, 0.05555, 23.71);
pub const mars = Celestial_Body.new(6.41693e23, 4.28284e4, 3.22282e-7, 3389.50, 3396.19, 3376.20, 2.27939e8, 2.06645e8, 2.49233e8, 686.97, 24.13, 0.09342, 1.85);
pub const jupiter = Celestial_Body.new(1.89852e27, 1.26713e8, 9.53510e-4, 69911, 71492, 66854, 7.78321e8, 7.40603e8, 8.16038e8, 4332.52, 13.06, 0.04846, 1.30);
pub const saturn = Celestial_Body.new(5.68460e26, 3.79406e7, 2.85502e-4, 58232, 60268, 54364, 1.42910e9, 1.35096e9, 1.50724e9, 10783.05, 9.64, 0.05468, 2.49);
pub const uranus = Celestial_Body.new(8.68192e25, 5.79456e6, 4.36039e-5, 25362, 25559, 24973, 2.87479e9, 2.73854e9, 3.01104e9, 30768.84, 6.79, 0.04739, 0.77);
pub const neptune = Celestial_Body.new(1.02431e26, 6.83653e6, 5.14447e-5, 24622, 24764, 24341, 4.50489e9, 4.46384e9, 4.54594e9, 60357.05, 5.43, 0.00911, 1.77);
pub const pluto = Celestial_Body.new(1.46158e22, 9.75500e2, 7.34061e-9, 1188.3, null, null, 5.91540e9, 4.44212e9, 7.38868e9, 90821.51, 4.74, 0.24906, 17.14);

test "Test Celestial Bodies Made" {
try std.testing.expectEqual(5.97219e24, earth.mass);
}

0 comments on commit 97c8f2f

Please sign in to comment.