Last active
December 20, 2015 06:09
-
-
Save dbuscombe-usgs/6083962 to your computer and use it in GitHub Desktop.
Destination point given distance and bearing from start point You have starting points:
xcoordinate, a list of x-coordinates (longitudes)
ycoordinate, a list of y-coordinates (latitudes)
num_samples, the number of samples in the plane towards the destination point bearings:
heading, a list of headings (degrees) and distances: range, a list of di…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R = 6371 % mean radius of the Earth, in km | |
% pre-allocate for results | |
x=cell(1,num_points) | |
y=cell(1,num_points) | |
for k=1:num_points | |
% COORDINATES OF STARTING POINT | |
lon1=xcoordinate(k) ; | |
lat1=ycoordinate(k) ; | |
d=range(k)/1000; %range in km | |
b1=heading(k); % bearing in degrees | |
% FIND FINAL BEARING FROM INITIAL BEARING | |
if b1=>180 | |
b2 = b1-180; | |
else | |
b2 = b1 + 180; | |
end | |
% CONVERT TO RADIANS | |
b1= b1.*(pi/180); | |
b2= b2.*(pi/180); | |
dOverR=d/R; % angular radians | |
% LATITUDE, END POINT 1 | |
lat2 = asin( sin(lat1*(pi/180))*cos(dOverR) + ... | |
cos(lat1*(pi/180))*sin(dOverR)*cos(b1) ) / (pi/180); | |
% LONGITUDE, END POINT 1 | |
lon2 = lon1 + atan2( sin(b1)*sin(dOverR)*cos(lat1), ... | |
cos(dOverR)-sin(lat1)*sin(lat2) ) ; | |
% LATITUDE, END POINT 2 | |
lat3 = asin( sin(lat1*(pi/180))*cos(dOverR) + ... | |
cos(lat1*(pi/180))*sin(dOverR)*cos(b2) ) / (pi/180); | |
% LONGITUDE, END POINT 2 | |
lon3 = lon1 + atan2( sin(b2)*sin(dOverR)*cos(lat1), ... | |
cos(dOverR)-sin(lat1)*sin(lat2) ) ; | |
% FIND COORDINATES IN THAT PLANE | |
y{k}=linspace( min([lat2,lat3]),max([lat2,lat3]), num_samples(k)); | |
x{k}=linspace( min([lon2,lon3]),max([lon2,lon3]), num_samples(k)); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment