function dist_km = gcircle_fn(data) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% USAGE: % % gcircle_fn([ lon1 lat1; lon2 lat2 ]) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % GCIRCLE v1.2 by Hamish Bowman June 7, 2000 % The sphere geodesic (great circle) to calculate the shortest distance betweem two % points on a shere. See http://mathworld.wolfram.com/GreatCircle.html % % This code is gifted to the public domain. % % Conventions: % degrees % N lat = + lat % S lat = - lat % E lon = lon % W lon = 360 - lon % % data = [ lon1 lat1; lon2 lat2 ] % ====== 2x2 matrix, column one is lons, 2 is lats. ====== % data = [ 287 42.0; 168 -45.6]; % NY to NZ % if( ~exist('data')) % note: need to pass gcircle_fn(data), not just in who!! disp('No data found. Using example as default.') disp('data = [ lon1 lat1; lon2 lat2 ];') break end %lon (western hemisphere is 360 - lon!) lam1 = data(1,1) * (2*pi/360); % convert to radians lam2 = data(2,1) * (2*pi/360); %lat del1 = data(1,2) * (2*pi/360); del2 = data(2,2) * (2*pi/360); r = 6367.444; % mean radius of the earth (km) R1dotR2 = cos(del1) * cos(del2) * cos(lam1-lam2) + sin(del1) * sin(del2); dist_km = r * acos( R1dotR2 );