# HG changeset patch
# User nschock <schocknol@gmail.com>
# Date 1393980694 28800
#      Tue Mar 04 16:51:34 2014 -0800
# Node ID 9543794219d18e4d12029543f48bf46f02033127
# Parent  037b67701b7293cf60c221660c338792be778bd8
2013-03-04 Nolan Schock <schocknol@gmail.com>

        * INDEX, NEWS, inst/km2rad.m, inst/rad2km.m
        New functions inst/km2rad.m and inst/rad2km.m

        * inst/km2rad.m, inst/rad2km.m
        New functions converting distance (kilometers) to angle (radians)
        and vice-versa.

diff -r 037b67701b72 -r 9543794219d1 inst/km2rad.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/km2rad.m	Tue Mar 04 16:51:34 2014 -0800
@@ -0,0 +1,48 @@
+## Copyright (C) 2014 Nolan Schock <schocknol@gmail.com>
+##
+## 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{rad} =} km2rad (@var{km})
+## @deftypefnx {Function File} {@var{rad} =} km2rad (@var{km}, @var{radius})
+## @deftypefnx {Function File} {@var{rad} =} km2rad (@var{km}, @var{sphere})
+## Convert distance to angle in radians.
+##
+## Calculates the angles @var{rad} for the distances @var{km} in a sphere with
+## @var{radius} (also in kilometers).  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{deg2km}
+## @end deftypefn
+
+## Author: Nolan Schock <nschock@gmail.com>
+
+function rad = km2rad (km, radius = "earth")
+  if (nargin < 1 || nargin > 2)
+    print_usage();
+  elseif (ischar (radius))
+    radius = spheres_radius(radius);
+  elseif(! isnumeric(radius) || ! isscalar (radius))
+    error ("km2rad: RADIUS must be a numeric scalar");
+  endif
+  rad = km / radius;
+endfunction
+
+%!assert (rad2km (km2rad (10)), 10, 10*eps)
+%!assert (rad2km (km2rad (10, 80), 80), 10, 10*eps)
+%!assert (rad2km (km2rad (10, "pluto"), "pluto"), 10, 10*eps)
diff -r 037b67701b72 -r 9543794219d1 inst/rad2km.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/rad2km.m	Tue Mar 04 16:51:34 2014 -0800
@@ -0,0 +1,47 @@
+## Copyright (C) 2014 Nolan Schock <schocknol@gmail.com>
+##
+## 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} =} rad2km (@var{km})
+## @deftypefnx {Function File} {@var{km} =} rad2km (@var{km}, @var{radius})
+## @deftypefnx {Function File} {@var{km} =} rad2km (@var{km}, @var{sphere})
+## Convert the radian angle to distance.
+##
+## Calculates the distances @var{km} in a sphere with @var{radius} (also in
+## kilometers) for the angles @var{rad}.  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{km2rad}
+## @end deftypefn
+
+## Author: Nolan Schock <nschock@gmail.com>
+
+function km = rad2km(rad, radius = "earth")
+  if (nargin < 1 || nargin > 2) 
+    print_usage();
+  elseif (ischar (radius))
+    radius = spheres_radius (radius);
+  elseif (! isnumeric(radius) || ! isscalar (radius))
+    error ("rad2km: RADIUS must be a numeric scalar");
+  endif
+  km = rad * pi;
+
+%!assert (km2rad (rad2km (10)), 10)
+%!assert (km2rad (rad2km (10, 80), 80), 10)
+%!assert (km2rad (rad2km (10, "pluto"), "pluto"), 10)
