%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Name: ecl2orb.m
% Author: J. Kristoffer Hultgren
%
% Description:
%
% Transforms coordinates from the ecliptic plane to the orbital plane
%
% Input: elem - Orbital elements [r inc omega]
% x,y,z - Coordinates in the ecliptic plane
%
% Output: [x2 y2 z2] - Coordinates in the orbital plane
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x2,y2,z2] = ecl2orb(elem,x,y,z)
omega = elem(3);
inc = elem(2);
% Rotation matrix
R = [cos(omega) -sin(omega)*cos(inc) sin(omega)*sin(inc);
sin(omega) cos(omega)*cos(inc) -cos(omega)*sin(inc);
0 sin(inc) cos(inc);];
Result = inv(R)*[x';y';z'];
x2 = Result(1,:);
y2 = Result(2,:);
z2 = Result(3,:);