function [P,V,S]=ellipsoidSphericity(D)
% ellipsoidSphericity <Sphericity of Elipse.>
% Usage:: [P,V,S]=ellipsoidSphericity(D)
%

% revision history:
% 08/17/95 Mark D. Shattuck <mds> ellipsoidSphericity.m
% 09/22/95 mds convert to vector D
% 10/28/12 mds use exact S formula from ellipseF/E

%% main

D=sort(D);

% approx
%p=1.6075;
%S=4*pi*(sum((D.*D([2 3 1],:)).^p)/3).^(1/p);

V=4*pi*prod(D)/3;

phi=acos(D(1,:)./D(3,:));
s=sin(phi);
D2=D.^2;
k=D2(3,:).*(D2(2,:)-D2(1,:))./D2(2,:)./(D2(3,:)-D2(1,:));
S=2*pi*D(1,:).^2+...
  2*pi*prod(D(2:3,:))./s.*(s.^2.*ellipticE(phi,k)+cos(phi).^2.*ellipticF(phi,k));

P=pi^(1/3)*(6*V).^(2/3)./S;
 