-
Notifications
You must be signed in to change notification settings - Fork 1
/
dg_cart2windpol.m
42 lines (35 loc) · 958 Bytes
/
dg_cart2windpol.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 [fangle, tangle, spd] = dg_cart2windpol(u,v)
%% synopsis: [fangle, tangle, spd] = dg_cart2windpol(u,v)
%%
%% this function calculate the from direction based the u and v component of the to velocity. north is up. useful for wind direction calculation
%% DG 20070320
%% DG 20101107 added speed output
%%
if nargin == 0
display('synopsis: function fangle = dg_cart2windpol(u,v)')
return;
end %if
rad = atan(v./u);
ang = rad*180/pi;
fangle = repmat(nan,size(ang));
ne = find(u >= 0 & v >= 0);
nw = find(u < 0 & v >= 0);
se = find(u >= 0 & v < 0);
sw = find(u < 0 & v < 0);
if ~isempty(ne)
tangle(ne) = 90-ang(ne);
fangle(ne) = tangle(ne) + 180;
end %if
if ~isempty(nw)
tangle(nw) = 270+abs(ang(nw));
fangle(nw) = tangle(nw) - 180;
end %if
if ~isempty(se)
tangle(se) = 90+abs(ang(se));
fangle(se) = tangle(se) + 180;
end %if
if ~isempty(sw)
tangle(sw) = 270-ang(sw);
fangle(sw) = tangle(sw) - 180;
end %if
spd = abs(u+i*v);