Mapping Toolbox 'distance' command inconsistent results with 'radians' units

I am currently performing some geographical coordinate calculations that use radians as their base units. In trying to leverage the distance command found in the Mapping Toolbox there seem to be some odd results when trying to utilize the 'radians' units option.
As an example, consider the fairly straightforward scenario.
[arclen, az] = distance(0,0,0,90);
The results for both 'arclen' and 'az' are 90 as would be expected. However if units are adjusted to 'radians' only the 'az' result appears appropriate.
[arclen, az] = distance(0,0,0,90,'radians');
The outcome for 'az' is the expected 1.5708. I was expecting 'arclen' to also show an answer of 1.5708, but instead the outcome 2.0354.
If a conversion from the default units output is applied to the 'arclen' and 'az' after the 'distance' calculation by employing 'deg2rad', both results are the expected 1.5708.
Am I misunderstanding something or is this indeed an error in conversion in the base 'distance' command when 'radians' is used for units?

 Accepted Answer

I have no experience with this toolbox/function, but I'm guessing you also need to treat the input units accordingly as radians. So, you probably actually needed
% Degrees
[arclen, az] = distance(0,0,0,90)
arclen = 90
az = 90
% Radians
[arclen, az] = distance(0,0,0,pi/2,'radians') % 90 deg = pi/2 radians
arclen = 1.5708
az = 1.5708

3 Comments

Actually the distance command is designed to take standard latitude and lognitude as inputs. It is interesting that your solution works and I can try that. However, that even points further to their being a problem. The whole idea is there is no need to do any adjustments to the latitude and longitude as part of the input process. All the examples in the MATLAB help demonstrate this - https://www.mathworks.com/help/map/ref/distance.html#d123e21918
I don't see an example there that uses the units input (explicitly as radians), and the description of the units input parameter explicitly states that unit is
"Angle units of the latitude and longitude coordinates, specified as 'degrees' or 'radians'."
Well there is the issue in that I misinterpreted 'units' as an output option versus input. Thanks for your time in putting another set of eyes on this.

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Asked:

on 8 Jan 2022

Commented:

on 8 Jan 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!