Code covered by the BSD License

# Geodetic Toolbox

### Mike Craymer (view profile)

13 Jun 2007 (Updated )

Toolbox for angle, coordinate and date conversions and transformations. Version 2.97.

dg2lg.m
```function [dx,dy]=dg2lg(dlat,dlon,lat,h,a,e2)
% DG2LG  Converts lat,lon,h to local geodetic coordinates.
%   Local origin at lat,lon.  If astronomic lat,h input,
%   then output is in local astronomic system.  Vectorized.
% Version: 2011-02-19
% Useage:  [dx,dy]=dg2lg(dlat,dlon,lat,h,a,e2)
%          [dx,dy]=dg2lg(dlat,dlon,lat,h)
% Input:   dlat - vector of latitude differences (rad)
%          dlon - vector of longitude differences (rad)
%          lat  - vector of lats of local system origins (rad)
%          h    - vector of hts of local system origins
%          a    - ref. ellipsoid major semi-axis (m); default GRS80
%          e2   - ref. ellipsoid eccentricity squared; default GRS80
% Output:  dx   - vector of x (N) coordinates in local system
%          dy   - vector of y (E) coordinates in local system

% Copyright (c) 2011, Michael R. Craymer
% Email: mike@craymer.com

if nargin ~= 4 & nargin ~= 6
warning('Incorrect number of input arguments');
return
end
if nargin == 4
[a,b,e2]=refell('grs80');
end

v=a./sqrt(1-e2.*sin(lat).^2);
r=v.*(1-e2)./(1-e2.*sin(lat).^2);
dx=dlat.*(r+h);
dy=dlon.*cos(lat).*(v+h);
```