Mercurial > forge
changeset 11528:f3d6682c340d octave-forge
deg2km: new function
author | carandraug |
---|---|
date | Sat, 09 Mar 2013 18:06:20 +0000 |
parents | d75c6d186696 |
children | b55a9cb1f799 |
files | extra/mapping/NEWS extra/mapping/inst/deg2km.m |
diffstat | 2 files changed, 55 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/mapping/NEWS Sat Mar 09 17:51:15 2013 +0000 +++ b/extra/mapping/NEWS Sat Mar 09 18:06:20 2013 +0000 @@ -1,6 +1,13 @@ Summary of important user-visible changes for mapping 1.2.0: ------------------------------------------------------------------- + ** The following functions are new in mapping 1.2.0: + + deg2km + ** The function `distance' has been greatly improved with more options including calculating the azimuth between points and support different angle units. + + ** The function km2deg can accept an optional radius or the name of some + Solar System objects.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/mapping/inst/deg2km.m Sat Mar 09 18:06:20 2013 +0000 @@ -0,0 +1,48 @@ +## Copyright (C) 2013 Carnë Draug <carandraug@octave.org> +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{km} =} deg2km (@var{deg}) +## @deftypefnx {Function File} {@var{km} =} deg2km (@var{deg}, @var{radius}) +## @deftypefnx {Function File} {@var{km} =} deg2km (@var{deg}, @var{sphere}) +## Convert angle to distance. +## +## Calculates the distances @var{km} in a sphere with @var{radius} (also in +## kilometers) for the angles @var{deg}. If unspecified, radius defaults to +## 6371, the mean radius of Earth. +## +## Alternatively, @var{sphere} can be one of "sun", "mercury", "venus", "earth", +## "moon", "mars", "jupiter", "saturn", "uranus", "neptune", or "pluto", in +## which case radius will be set to that object mean radius. +## +## @seealso{km2deg} +## @end deftypefn + +## Author: Alexander Barth <barth.alexander@gmail.com> + +function km = deg2km (deg, radius = "earth") + if (nargin < 1 || nargin > 2) + print_usage(); + elseif (ischar (radius)) + radius = spheres_radius (radius); + elseif (! isnumeric (radius) || ! isscalar (radius)) + error ("deg2km: RADIUS must be a numeric scalar"); + endif + km = (deg * pi * radius) / 180; +endfunction + +%!assert (km2deg (deg2km (10)), 10) +%!assert (km2deg (deg2km (10, 80), 80), 10) +%!assert (km2deg (deg2km (10, "pluto"), "pluto"), 10)