-
Notifications
You must be signed in to change notification settings - Fork 3
/
ECI2Hill.m
54 lines (36 loc) · 1.28 KB
/
ECI2Hill.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
%% ECI2LVLH - ECI to LVLH frame conversion and vice-versa
% Inputs:
% X1: Reference Frame Pos,Vel in ECI
% X2: Object Pos,Vel in ECI if reverse not true
% Object relative Pos,Vel in LVLH frame if reverse true
% Omega: Reference frame angular velocity expressed in LVLH frame
% reverse: true for converting from LVLH to ECI
% Units: rad, km, sec
% Tolerance: 1e-12
% Author: Bharat Mahajan (https://github.com/princemahajan)
function [ Y ] = ECI2Hill( X1, X2, reverse )
% form DCM
rcap = X1(1:3,1)'/norm(X1(1:3));
hvec = cross(X1(1:3,1)',X1(4:6,1)');
hcap = hvec/norm(hvec);
tcap = cross(hcap,rcap);
DCM = [rcap; tcap; hcap];
Omega = [0;0;norm(hvec)/norm(X1(1:3))^2];
if reverse == true
% convert from LVLH to ECI
% ECI pos
Y(1:3,1) = DCM'*X2(1:3,1) + X1(1:3,1);
% Inertial relative velocity expressed in LVLH
Y(4:6,1) = X2(4:6,1) + cross(Omega,X2(1:3,1));
% ECI velocity in ECI frame
Y(4:6,1) = DCM'*Y(4:6,1) + X1(4:6,1);
else
% convert from ECI to LVLH
% inertial difference vector
dX = X2 - X1;
% LVLH pos
Y(1:3,1) = DCM*dX(1:3,1);
% LVLH vel
Y(4:6,1) = DCM*dX(4:6,1) - cross(Omega,Y(1:3,1));
end
end