Home > matGeom > geom3d > createSphere.m

createSphere

PURPOSE ^

CREATESPHERE Create a sphere containing 4 points.

SYNOPSIS ^

function sphere = createSphere(varargin)

DESCRIPTION ^

CREATESPHERE Create a sphere containing 4 points.

   s = createSphere(p1, p2, p3, p4);
   return in s the sphere common to the 4 pointsp1, p2, p3 and p4.

   Ref: P. Bourke
   http://astronomy.swin.edu.au/~pbourke/geometry/spherefrom4/

   See also
   spheres, circles3d

   ---------
   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 22/03/2005.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function sphere = createSphere(varargin)
0002 %CREATESPHERE Create a sphere containing 4 points.
0003 %
0004 %   s = createSphere(p1, p2, p3, p4);
0005 %   return in s the sphere common to the 4 pointsp1, p2, p3 and p4.
0006 %
0007 %   Ref: P. Bourke
0008 %   http://astronomy.swin.edu.au/~pbourke/geometry/spherefrom4/
0009 %
0010 %   See also
0011 %   spheres, circles3d
0012 %
0013 %   ---------
0014 %   author : David Legland
0015 %   INRA - TPV URPOI - BIA IMASTE
0016 %   created the 22/03/2005.
0017 %
0018 
0019 
0020 if length(varargin)==4
0021     pts = [varargin{1};varargin{2};varargin{3};varargin{4}];
0022 elseif length(varargin)==1
0023     pts = varargin{1};
0024 else
0025     error('wrong number of arguments in createSphere');
0026 end
0027 
0028 
0029 m1 = det([pts ones(4,1)]);
0030 s2 = sum(pts.*pts, 2);
0031 m2 = det([s2 pts(:,2) pts(:,3) ones(4,1)]);
0032 m3 = det([pts(:,1) s2 pts(:,3) ones(4,1)]);
0033 m4 = det([pts(:,1) pts(:,2) s2 ones(4,1)]);
0034 
0035 m5 = det([s2 pts]);
0036 
0037 x0 = m2*.5/m1;
0038 y0 = m3*.5/m1;
0039 z0 = m4*.5/m1;
0040 r  = sqrt(x0*x0 + y0*y0 + z0*z0 - m5/m1);
0041 
0042 sphere = [x0 y0 z0 r];

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019