1 ## Copyright (C) 2004 Andrew Collier <abcollier@users.sourceforge.net>
3 ## This program is free software; it is distributed in the hope that it
4 ## will be useful, but WITHOUT ANY WARRANTY; without even the implied
5 ## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
6 ## the GNU General Public License for more details.
8 ## You should have received a copy of the GNU General Public License
9 ## along with this file; see the file COPYING. If not, see
10 ## <http://www.gnu.org/licenses/>.
13 ## @deftypefn {Function File} {} @var{az} = azimuth(@var{lat1},@var{lon1},@var{lat2},@var{lon2})
14 ## @deftypefnx {Function File} {} @var{az} = azimuth(@var{lat1},@var{lon1},@var{lat2},@var{lon2},@var{units})
15 ## @deftypefnx {Function File} {} @var{az} = azimuth(@var{pt1}, @var{pt2})
16 ## @deftypefnx {Function File} {} @var{az} = azimuth(@var{pt1}, @var{pt2},@var{units})
18 ## Calculates the great circle azimuth from a point 1 to a point 2.
19 ## The latitude and longitude of these two points can either be given
20 ## independently or as columns of the matrices @var{pt1} and @var{pt2} in
21 ## the form [latitude longitude].
23 ## The units for the input coordinates and output angles can be
24 ## "degrees" (the default) or "radians".
27 ## >> azimuth([10,10], [10,40])
29 ## >> azimuth([0,10], [0,40])
31 ## >> azimuth(pi/4,0,pi/4,-pi/2,"radians")
35 ## @seealso{elevation,distance}
38 ## Author: Andrew Collier <abcollier@users.sourceforge.net>
39 ## Adapted-by: Alexander Barth <abarth93@users.sourceforge.net>
41 ## Uses "four-parts" formula.
43 function az = azimuth(varargin)
44 ## default units are degrees
48 [reg,prop] = parseparams(varargin);
56 C = pt2(:,2) - pt1(:,2);
57 elseif length(reg) == 4
62 error("Wrong number of type of arguments");
68 if (~strcmp(units,"degrees") & ~strcmp(units,"radians"))
69 error("Only degrees and radians are allowed as units");
71 elseif length(prop) > 1
72 error("Wrong number of type of arguments");
75 if (strcmp(units,"degrees"))
81 az = atan2(sin(C) , cos(a) .* tan(b) - sin(a) .* cos(C) );
83 ## bring the angle in the interval [0 2*pi[
87 ## convert to degrees if desired
89 if (strcmp(units,"degrees"))
94 ## http://www.mathworks.com/access/helpdesk/help/toolbox/map/azimuth.shtml