Skip to content

Instantly share code, notes, and snippets.

@geoffreygarrett
Created December 5, 2019 15:43
Show Gist options
  • Save geoffreygarrett/c3ae2c7edc3af81c39e31718d323db30 to your computer and use it in GitHub Desktop.
Save geoffreygarrett/c3ae2c7edc3af81c39e31718d323db30 to your computer and use it in GitHub Desktop.
MATLAB Conversion from classical orbital elements into RV.
function [r,v] = coe2rv(a, e, inc, raan, argp, theta, mu)
cos_raan = cos(raan);
sin_raan = sin(raan);
cos_argp = cos(argp);
sin_argp = sin(argp);
cos_inc = cos(inc);
sin_inc = sin(inc);
r = a * (1 - e ^ 2) / (1.0 + e * cos(theta));
l1 = (+cos_raan * cos_argp - sin_raan * sin_argp * cos_inc);
l2 = (-cos_raan * sin_argp - sin_raan * cos_argp * cos_inc);
m1 = (+sin_raan * cos_argp + cos_raan * sin_argp * cos_inc);
m2 = (-sin_raan * sin_argp + cos_raan * cos_argp * cos_inc);
n1 = sin_argp * sin_inc;
n2 = cos_argp * sin_inc;
aux = [r * cos(theta); r * sin(theta)];
transformation = [l1, l2;...
m1, m2;...
n1, n2];
% Position
xyz = transformation * aux;
x = xyz(1);
y = xyz(2);
z = xyz(3);
% Velocity
H = sqrt(mu * a * (1 - e ^ 2));
v_x = mu / H * (-l1 * sin(theta) + l2 * (e + cos(theta)));
v_y = mu / H * (-m1 * sin(theta) + m2 * (e + cos(theta)));
v_z = mu / H * (-n1 * sin(theta) + n2 * (e + cos(theta)));
r = [x, y, z];
v = [v_x, v_y, v_z];
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment