function [e, n, u] = rot2enu(X, Y, Z, x, y, z)
%function [e, n, u] = rot2enu(X, Y, Z, x, y, z)
%
%Rotates the vector [x, y, z]' to the local east-north-up
%system at [X, Y, Z]'.
%

[lat, lon, h] = xyz2llh(X, Y, Z);
sphi = sin(lat);
cphi = cos(lat);
slmb = sin(lon);
clmb = cos(lon);

T = [-slmb, clmb, 0;  -sphi*clmb , -sphi*slmb, cphi; cphi*clmb, cphi*slmb, sphi];

enu = T*[x, y, z]';
e = enu(1);
n = enu(2);
u = enu(3);
