-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCelestialObject.m
77 lines (62 loc) · 2.33 KB
/
CelestialObject.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
classdef CelestialObject
% This class defines a celestial object in heliocentric trajectory
% and contains the physical properties.
properties
name
mass
r
r_soi
r_orbit
tilt
w_orbit
T_orbit
mu
mu_sun
t_anomaly
heliocentric_pos
heliocentric_vel
end
methods
function obj = CelestialObject(name, mass, r, r_orbit, tilt, jdt)
% Constants
m_sun = 1.98847e30; % kg
G = 6.6743015e-20; % km^3 k^-1 s^-2
mu_sun = m_sun * G;
% Initialize properties
obj.mass = mass;
obj.mu = mass * G;
obj.r = r;
obj.r_orbit = r_orbit;
obj.r_soi = obj.r_orbit * (mass / m_sun)^(2/5);
obj.T_orbit = 2 * pi * obj.r_orbit^1.5 / sqrt(mu_sun);
obj.w_orbit = sqrt(mu_sun/r_orbit) / r_orbit;
obj.name = name;
obj.mu_sun = mu_sun;
obj.tilt = tilt;
% True anomaly calculation
pos = planetEphemeris(jdt, "SolarSystem", obj.name);
obj.t_anomaly = rad2deg(angle(pos(1)+ 1i * pos(2)));
if obj.t_anomaly < 0
obj.t_anomaly = obj.t_anomaly + 360;
end
% Heliocentric position calculation
obj.heliocentric_pos = [obj.r_orbit * cosd(obj.t_anomaly), ...
obj.r_orbit * sind(obj.t_anomaly), 0];
% Heliocentric velocity calculation
obj.heliocentric_vel = sqrt(mu_sun / obj.r_orbit) * ...
[-sind(obj.t_anomaly), ...
cosd(obj.t_anomaly), 0];
end
function obj = refresh(obj, t)
obj.t_anomaly = obj.t_anomaly + rad2deg(obj.w_orbit * t);
if obj.t_anomaly > 360
obj.t_anomaly = obj.t_anomaly - 360;
end
obj.heliocentric_pos = [obj.r_orbit * cosd(obj.t_anomaly), ...
obj.r_orbit * sind(obj.t_anomaly), 0];
obj.heliocentric_vel = sqrt(obj.mu_sun / obj.r_orbit) * ...
[-sind(obj.t_anomaly), ...
cosd(obj.t_anomaly), 0];
end
end
end