How do I get directionality from the departure() function
1 view (last 30 days)
Show older comments
I have two sets of coordinates and I need to calculate the distance between them in longitude converted to meters. The departure() function serves this purpose well. However, it returns all positive values for distance regardless of which coordinate is more east/west than the other. Is there a way I can get directionality from this function, or by altering the output in some indexed way?
lat1=[45.73366;42.30074;42.11033;37.69088];
lon1=[-115.85149;-115.54721;-108.03860;-96.52568];
lat2=[45.94414;41.20918;42.64974;36.66341];
lon2=[-115.28569;-116.87984;-108.61347;-95.06520];
coords=table(lat1,lon1,lat2,lon2)
coords.lon_diff_m=departure(coords.lon1,coords.lon2,(coords.lat1+coords.lat2)./2,wgs84Ellipsoid,'degrees')
%output in meters since wgs84Ellipsoid uses meters for semi-major axis definition
%average latitudes for longitudinal distance calculation
As you can see, all the distances are positive values. I would like the output to be directional where, if coordinate 1 is west of coordinate 2 the output is negative, and if coordinate 1 is east of coordinate 2 the output is positive.
I suppose I could use an index vector of lat1<lat2 to multiply the rows that qualify by -1.
idx=(coords.lon1<coords.lon2);
coords.lon_diff_m(idx)=coords.lon_diff_m(idx).*-1
I came up with this answer as I am writing this question. However, if anybody has a better way to do this or sees an error in my method, please let me know.
0 Comments
Accepted Answer
William Rose
on 7 Mar 2023
Multiply the values from departure by sign(lon1-lon2).
Define points:
lat1=[45.73366;42.30074;42.11033;37.69088];
lon1=[-115.85149;-115.54721;-108.03860;-96.52568];
lat2=[45.94414;41.20918;42.64974;36.66341];
lon2=[-115.28569;-116.87984;-108.61347;-95.06520];
Compute longitude difference with +/-:
lon_diff_m=departure(lon1,lon2,(lat1+lat2)/2,wgs84Ellipsoid,'degrees').*sign(lon1-lon2)
That works.
1 Comment
William Rose
on 7 Mar 2023
@Steve K, departure() is useful if you are doing latitude sailing, as was common pre-good-chronometers, i.e. pre-1730s. Nowadays one would sail or fly a great circle track. What is the current usefulness of departure()? Surveying? Hiking the Mason Dixon line, or the 49th parallel?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!