-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrbit.m
More file actions
42 lines (37 loc) · 1.33 KB
/
Orbit.m
File metadata and controls
42 lines (37 loc) · 1.33 KB
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
classdef Orbit < matlab.mixin.Heterogeneous % to allow arrays of mixed classes
properties
sma; % semi-major axis [m]
ecc; % eccentricity
inc; % inclination [rad]
arg; % argument of periapsis [rad]
lan; % longitude of ascending node [rad]
mna; % mean anomaly at epoch J2000 [rad]
end
methods
% Constructor
function obj = Orbit(sma, ecc, inc, arg, lan, mna)
obj.sma = sma;
obj.ecc = ecc;
obj.inc = inc;
obj.arg = arg;
obj.lan = lan;
obj.mna = mna;
end
function [r, v] = toIJK(obj, p, tea, mu)
% norm
r_mag = p / (1 + obj.ecc * cos(tea));
v_mag = sqrt(mu / p);
% local
r_loc = r_mag * [cos(tea); sin(tea); 0];
v_loc = v_mag * [-sin(tea); obj.ecc + cos(tea); 0];
% rotation
R1 = [cos(-obj.lan) sin(-obj.lan) 0; -sin(-obj.lan) cos(-obj.lan) 0; 0 0 1];
R2 = [1 0 0; 0 cos(-obj.inc) sin(-obj.inc); 0 -sin(-obj.inc) cos(-obj.inc)];
R3 = [cos(-obj.arg) sin(-obj.arg) 0; -sin(-obj.arg) cos(-obj.arg) 0; 0 0 1];
R = R1 * R2 * R3;
% global
r = R * r_loc;
v = R * v_loc;
end
end
end