## Copyright (C) 2017 Anonymous (adjust accordingly)
##
## 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; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {} axes2ecc ( @var{semimajor} , @var{semiminor} )
##
## Calculates the eccentricity from semimajor and semiminor axes
##
## @example
## >> axes2ecc ( 6378137 , 6356752.314245 )
## ans =   0.0818191908429654
## @end example
## 
## Also can be done in vector form
## @example
## >> axes2ecc ( [6378137, 6356752.314245] )
## ans =   0.0818191908429654
## @end example
## 
## Also for multivectors
## @example
## >> axes2ecc ( [ 71492  , 66854;
##                 6378137, 6356752.314245] )
## ans =
##
##     0.354316378965041
##    0.0818191908429654
## @end example
##               
## @seealso(ecc2flat,flat2ecc,majaxis,minaxis)
## @end deftypefn
function ecc = axes2ecc ( semimajor , semiminor )
  if nargin < 1
    print_usage ();
  elseif nargin == 1
    s = size ( semimajor );
    if s( 2 ) != 2
      error (' Must be a nx2 matrix');
    end
    ecc = zeros ( s ( 1 ) , 1 );
    for i = 1 : s(1)
    ecc( i ) = sqrt ( ( semimajor( i , 1) .^ 2 - semimajor( i , 2) .^ 2 ) / ( semimajor( i , 1) .^ 2 ) );
    end
  else
    if ( ischar ( semimajor ) || ischar ( semiminor ) )
    error ('Cannot be strings');
    end
    ecc = sqrt ( ( semimajor ^ 2 - semiminor ^ 2 ) / ( semimajor ^ 2 ) );
  end
endfunction


%!test
%!
%! semimajor = 6378137;
%! semiminor = 6356752.314245;
%! Earth = [ semimajor , semiminor ];
%! Jupiter = [ 71492 , 66854 ];
%! Planets = [ Jupiter ; Earth ];
%! assert( axes2ecc( semimajor , semiminor ), 0.0818191908429654 , 10^-12 )
%! assert( axes2ecc( Earth ), 0.0818191908429654 , 10^-12 )
%! assert( axes2ecc( Planets ), [ 0.354316379 ; 0.081819791 ], 10^-10 )
