function [x,y]=ll2xy(lat, lon, ref);
%ll2xy.m
%
% [x,y]=ll2xy(lat, lon, ref);
%
%Converts latitude and longitude coordinates to x,y in meters relative
%to some reference position. 

n=length(lat);

R= 6378.155*1000;    %Radius at equator is 6378.155 km

R2=R*cos(ref(1)*pi/180);

x=(lon-ref(2))/360 * 2*pi*R2;  	%X
y=(lat-ref(1))/360 * 2*pi*R;		%Y
