  function [X, Y, Z] = llh2xyz(lat, lon, h)
% function [Z, Y, Z] = llh2xyz(lat, lon, h)
%
%Converts latitude, longitude, height to XYZ coordinates  
%
% Input:
%	lat, lon in decimal degrees, height in meters
%
% Output:
%	coordinates in meters
%

% semi-major and minor axes
a = 6378137.0;
f = 1.0/298.2572235630;
b = (1-f)*a;

% convert degrees to radians
phi = lat*pi/180;
lam = lon*pi/180;

N = a^2/sqrt( a^2*cos(phi)^2 + b^2*sin(phi)^2);

X = (N+h)*cos(phi)*cos(lam);
Y = (N+h)*cos(phi)*sin(lam);
Z = ( b^2*N/a^2 + h )*sin(phi);
