-
Notifications
You must be signed in to change notification settings - Fork 10
/
gibbs.m
91 lines (74 loc) · 2.48 KB
/
gibbs.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function [a,i,e,omega,w,theta] = gibbs(R1,R2,R3,mu)
%% Gibbs method for finding velocities of an orbit
%
% Jeremy Penn
% 20 October 2017
%
% Revision 20/10/17
%
% function [a,i,e,omega,w,theta] = gibbs(R1,R2,R3,mu)
%
% Purpose: This function computes the classical orbital elements by
% means of the Gibbs method.
%
% Inputs: o R1 - A 1x3 vector describing the 1st position of the
% satellite.
% o R2 - A 1x3 vector describing the 2nd position of the
% satellite.
% o R3 - A 1x3 vector describing the 3rd position of the
% satellite.
% o mu - The standard gravitational parameter [OPTIONAL].
% Defaults to Earth.
%
% Output: o a - Semi-major axis
% o i - inclination
% o e - eccintricity
% o omega - right ascension of the ascending node
% o w - argument of perigee
% o theta - true anomaly
%
% Requires: kepler_convert.m
%
clc;
if nargin == 3
mu = 398600;
end
tol = 1e4;
%% Calculate magnitudes of r1,r2, and r3
r1 = norm(R1);
r2 = norm(R2);
r3 = norm(R3);
%% Confirm they comprise an orbit
c12 = cross(R1,R2);
c23 = cross(R2,R3);
c31 = cross(R3,R1);
ur1 = R1/r1;
nc23 = norm(c23);
uc23 = c23/nc23;
if abs(dot(ur1,uc23)) > tol
error('Error: The given positions do not describe an orbit');
end
%% Calculate N, D, and S vectors
N = r1*c23 + r2*c31 + r3*c12;
D = c12 + c23 + c31;
S = R1*(r2-r3) + R2*(r3-r1) + R3*(r1-r2);
n = norm(N);
d = norm(D);
%% Compute velocity at r2
dr2 = cross(D,R2);
V2 = sqrt(mu/(n*d))*((dr2/r2) + S);
%% Calculate the orbital elements from r2 and v2
kepler = kepler_convert(R2,V2);
a = kepler(1);
e = kepler(2);
i = kepler(3);
omega = kepler(4);
w = kepler(5);
theta = kepler(6);
fprintf('The semimajor axis is %5f [km]\n', a)
fprintf('The eccentricity is %1.2f [deg]\n', e)
fprintf('The inclination is %3.2f [deg]\n', i)
fprintf('The right ascension of the ascending node is %3.2f [deg]\n', omega)
fprintf('The argument of perigee is %3.2f [deg]\n', w)
fprintf('The true anomaly is %3.2f [deg]\n', theta)
end