X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fmapping-1.0.7%2Fdistance.m;fp=octave_packages%2Fmapping-1.0.7%2Fdistance.m;h=8b726aefde5194d11695db30715aee27e2be7a79;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/mapping-1.0.7/distance.m b/octave_packages/mapping-1.0.7/distance.m new file mode 100644 index 0000000..8b726ae --- /dev/null +++ b/octave_packages/mapping-1.0.7/distance.m @@ -0,0 +1,44 @@ +## Copyright (C) 2004 Andrew Collier +## +## This program is free software; it is distributed in the hope that it +## will be useful, but WITHOUT ANY WARRANTY; without even the implied +## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +## the GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this file; see the file COPYING. If not, see +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} @var{dist} = distance(@var{pt1}, @var{pt2}) +## +## Calculates the distance (in degrees) between @var{pt1} and @var{pt2}. +## +## @var{pt1} and @var{pt2} are two-column matrices of the form [latitude longitude]. +## +## @example +## >> distance([37,-76], [37,-9]) +## ans = 52.309 +## >> distance([37,-76], [67,-76]) +## ans = 30.000 +## @end example +## +## @seealso{azimuth,elevation} +## @end deftypefn + +## Author: Andrew Collier + +## Uses "cosine formula". + +function dist = distance(pt1, pt2) + pt1 = deg2rad(pt1); + pt2 = deg2rad(pt2); + + c = pi / 2 - pt1(1); + b = pi / 2 - pt2(1); + A = pt2(2) - pt1(2); + + dist = rad2deg(acos(cos(b) * cos(c) + sin(b) * sin(c) * cos(A))); +endfunction + +## http://www.mathworks.com/access/helpdesk/help/toolbox/map/distance.shtml