-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWgsxyz2enu.m
51 lines (36 loc) · 1.26 KB
/
Wgsxyz2enu.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
43
44
45
46
47
48
49
50
51
% Function enu = wgsxyz2enu(xyz, reflat, reflon, refalt) returns
% a 3 x 1 vector enu which represents the East, North, and Up
% coordinates (in meters) of a point with WGS84 xyz coordinates
% xyz (3 x 1 vector, units in meters) in an ENU coordinate system
% located at latitude reflat (degrees), longitude reflon (degrees)
% and altitude above the WGS84 ellipsoid refalt (meters)
%
% Note: Requires functions wgslla2xyz.m and rot.m to be in the
% same directory
function enu=Wgsxyz2enu(xyz, reflat, reflon, refalt)
[m n] = size(xyz);
if m ~= 3 | n ~= 1
error('wgsxyz2enu: xyz input vector must be 3 x 1');
end
[m n] = size(reflat);
if m ~= 1 | n ~= 1
error('wgsxyz2enu: reflat input vector must be scalar');
end
[m n] = size(reflon);
if m ~= 1 | n ~= 1
error('wgsxyz2enu: reflon input vector must be scalar');
end
[m n] = size(refalt);
if m ~= 1 | n ~= 1
error('wgsxyz2enu: refalt input vector must be scalar');
end
% First, calculate the xyz of reflat, reflon, refalt
refxyz = Wgslla2xyz(reflat, reflon, refalt);
% Difference xyz from reference point
diffxyz = xyz - refxyz;
% Now rotate the (often short) diffxyz vector to enu frame
R1=rot(90+reflon, 3);
R2=rot(90-reflat, 1);
R=R2*R1;
enu=R*diffxyz;
return;