-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrbitalElements.m
33 lines (28 loc) · 972 Bytes
/
OrbitalElements.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
classdef OrbitalElements
% Initializing this object with the state vector and the center body
% returns the orbital elements in properties.
properties
h_vector
h
e_vector
e
r_periapsis
r_apoapsis
period
a
end
methods
function obj = OrbitalElements(X_i, V_i, mu)
% Calculate orbital elements
obj.h_vector = cross(X_i, V_i);
obj.h = norm(obj.h_vector);
V_ri = dot(X_i/norm(X_i), V_i);
obj.e_vector = (1/mu) * ((norm(V_i)^2 - mu / norm(X_i)) * X_i - norm(X_i) * V_ri * V_i);
obj.e = norm(obj.e_vector);
obj.r_apoapsis = (obj.h^2 / mu) ./ (1 + obj.e * cosd(180));
obj.r_periapsis = (obj.h^2 / mu) ./ (1 + obj.e * cosd(0));
obj.a = 0.5 * (obj.r_periapsis + obj.r_apoapsis);
obj.period = sqrt(obj.a^3 * 4 * pi^2 / mu);
end
end
end