-
Notifications
You must be signed in to change notification settings - Fork 6
/
llh2xyz.m
34 lines (29 loc) · 1.34 KB
/
llh2xyz.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [XYZ] = llh2xyz( LLH )
%*************************************************************************
%* Copyright c 2001 The board of trustees of the Leland Stanford *
%* Junior University. All rights reserved. *
%* This script file may be distributed and used freely, provided *
%* this copyright notice is always kept with it. *
%* *
%* Questions and comments should be directed to Todd Walter at: *
%* [email protected] *
%*************************************************************************
%
% function [XYZ] = llh2xyz( LLH )
%
% Calculate location in ECEF given location in Lat Lon Height.
% Input: Matrix LLH: Latitude [ ], Longitude [ ], Height [m]
%One row for each point to be converted
% Output: Matrix XYZ [m] in ECEF: One row for each point
re = 6378137.0; % Earth equatorial radius
eflat = (1.0/298.257223563); % Earth Flattening
lat= LLH(:,1);
lon = LLH(:,2);
ht = LLH(:,3);
e2 = (2- eflat)* eflat;
slat = sin(lat);
clat = cos(lat);
r_N = re./sqrt( 1 - e2*slat.*slat );
XYZ(:,1) = ( r_N+ ht ).*clat.*cos(lon);
XYZ(:,2) = ( r_N+ ht ).*clat.*sin(lon);
XYZ(:,3) = ( r_N*(1-e2)+ ht ).*slat;