-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathenu2xyz.m
42 lines (40 loc) · 1.42 KB
/
enu2xyz.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
35
36
37
38
39
40
41
42
function xyz = enu2xyz(enu,orgxyz)
%ENU2XYZ Convert from rectangular local-level-tangent
% ('East'-'North'-Up) coordinates to WGS-84
% ECEF cartesian coordinates.
%
% xyz = ENU2XYZ(enu,orgxyz)
%
% enu(1) = 'East'-coordinate relative to local origin (meters)
% enu(2) = 'North'-coordinate relative to local origin (meters)
% enu(3) = Up-coordinate relative to local origin (meters)
%
% orgxyz(1) = ECEF x-coordinate of local origin in meters
% orgxyz(2) = ECEF y-coordinate of local origin in meters
% orgxyz(3) = ECEF z-coordinate of local origin in meters
%
% xyz(1,1) = ECEF x-coordinate in meters
% xyz(2,1) = ECEF y-coordinate in meters
% xyz(3,1) = ECEF z-coordinate in meters
% Reference: Alfred Leick, GPS Satellite Surveying, 2nd ed.,
% Wiley-Interscience, John Wiley & Sons,
% New York, 1995.
%
% M. & S. Braasch 10-96
% Copyright (c) 1996 by GPSoft
% All Rights Reserved.
if nargin<2,error('insufficient number of input arguments'),end
[m,n]=size(enu);if m<n,tmpenu=enu';else,tmpenu=enu;end
[m,n]=size(orgxyz);if m<n,tmpxyz=orgxyz';else,tmpxyz=orgxyz;end
orgllh = xyz2llh(tmpxyz);
phi = orgllh(1);
lam = orgllh(2);
sinphi = sin(phi);
cosphi = cos(phi);
sinlam = sin(lam);
coslam = cos(lam);
R = [ -sinlam coslam 0 ; ...
-sinphi*coslam -sinphi*sinlam cosphi; ...
cosphi*coslam cosphi*sinlam sinphi];
difxyz = inv(R)*tmpenu;
xyz = tmpxyz + difxyz;