computetrackstats.m

来自「基于串行接口的GPS驱动程序」· M 代码 · 共 39 行

M
39
字号
function [ distance, time ] = ComputeTrackStats(track)
% COMPUTETRACKSTATS Compute track log statistics
%
% Compute the length of the track, and the time spent traversing it.
% Sometimes the time may be zero, because Garmin GPS units remove the
% timestamp from saved track logs (though they maintain it in the 
% active log).

distance = 0;
time = 0;
for i=1:length([track.waypoints.lat])-1
    distance = distance + SphericalDistance(track.waypoints(i), track.waypoints(i+1));
end
% Time stamp stored as seconds, simply subtract end from beginning to
% get duration. 
seconds = track.waypoints(i).time - track.waypoints(1).time;
% Covert to hours
time = seconds / 3600;

function d = SphericalDistance(point1, point2)
% SPHERICALDISTANCE Compute the distance between two points on the Earth's 
% surface Earth's radius:
%   3437.74677 statue miles
%   6378 kilometers
%   3963 normal miles

% Convert to radians.
deg2rad = (180/pi); 
lat1 = point1.lat / deg2rad; 
long1 = point1.long / deg2rad;
lat2 = point2.lat / deg2rad;
long2 = point2.long / deg2rad;

% Compute distance in miles
r = 3963;
d = acos( sin(lat1) * sin(lat2) + ...
          cos(lat1)*cos(lat2)*cos(long2-long1) ) * r;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?