1## Copyright (C) 2013-2020 Alexander Barth 2## Copyright (C) 2018-2020 Philip Nienhuis 3## 4## This program is free software; you can redistribute it and/or modify it under 5## the terms of the GNU General Public License as published by the Free Software 6## Foundation; either version 3 of the License, or (at your option) any later 7## version. 8## 9## This program is distributed in the hope that it will be useful, but WITHOUT 10## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 12## details. 13## 14## You should have received a copy of the GNU General Public License along with 15## this program; if not, see <http://www.gnu.org/licenses/>. 16 17## -*- texinfo -*- 18## @deftypefn {Function File} {@var{sm} =} deg2sm (@var{deg}) 19## @deftypefnx {Function File} {@var{sm} =} deg2sm (@var{deg}, @var{radius}) 20## @deftypefnx {Function File} {@var{sm} =} deg2sm (@var{deg}, @var{sphere}) 21## Converts angle n degrees to distance in statute miles by multiplying angle 22## with radius. 23## 24## Calculates the distances @var{sm} in a sphere with @var{radius} (also in 25## statute miles) for the angles @var{deg}. If unspecified, radius defaults to 26## 3958 sm, the mean radius of Earth. 27## 28## Alternatively, @var{sphere} can be one of "sun", "mercury", "venus", "earth", 29## "moon", "mars", "jupiter", "saturn", "uranus", "neptune", or "pluto", in 30## which case radius will be set to that object's mean radius. 31## 32## @seealso{deg2km, deg2nm, km2rad, km2deg, 33## nm2deg, nm2rad, rad2km, rad2nm, rad2sm, sm2deg, sm2rad} 34## @end deftypefn 35 36## Built with insight from 37## Author: Alexander Barth <barth.alexander@gmail.com> 38## Adapted from deg2km.m by Anonymous contributor, see patch #9709 39 40function sm = deg2sm (deg, radius = "earth") 41 42 ## Check arguments 43 if (nargin < 1 || nargin > 2) 44 print_usage(); 45 elseif (ischar (radius)) 46 ## Get radius of sphere with its default units (km) 47 radius = km2sm (spheres_radius (radius)); 48 ## Check input 49 elseif (! isnumeric (radius) || ! isreal (radius)) 50 error ("deg2sm: RADIUS must be a numeric scalar"); 51 endif 52 sm = (deg2rad (deg) * radius); 53 54endfunction 55 56 57%!test 58%!assert (sm2deg (deg2sm (10)), 10, 10*eps); 59%!assert (sm2deg (deg2sm (10, 80), 80), 10, 10*eps); 60%!assert (sm2deg (deg2sm (10, "pluto"), "pluto"), 10, 10*eps); 61 62%!error <RADIUS> deg2sm (5, 5i) 63