Home > matGeom > geom3d > intersectPlaneSphere.m

intersectPlaneSphere

PURPOSE ^

INTERSECTPLANESPHERE Return intersection circle between a plane and a sphere.

SYNOPSIS ^

function circle = intersectPlaneSphere(plane, sphere)

DESCRIPTION ^

INTERSECTPLANESPHERE Return intersection circle between a plane and a sphere.

   CIRC = intersectPlaneSphere(PLANE, SPHERE)
   Returns the circle which is the intersection of the given plane
   and sphere. 
   PLANE  : [x0 y0 z0  dx1 dy1 dz1  dx2 dy2 dz2]
   SPHERE : [XS YS ZS  RS]
   CIRC   : [XC YC ZC  RC  THETA PHI PSI]
   [x0 y0 z0] is the origin of the plane, [dx1 dy1 dz1] and [dx2 dy2 dz2]
   are two direction vectors,
   [XS YS ZS] are coordinates of the sphere center, RS is the sphere
   radius, 
   [XC YC ZC] are coordinates of the circle center, RC is the radius of
   the circle, [THETA PHI] is the normal of the plane containing the
   circle (THETA being the colatitude, and PHI the azimut), and PSI is a
   rotation angle around the normal (equal to zero in this function, but
   kept for compatibility with other functions). All angles are given in
   degrees.
   
   See Also:
   planes3d, spheres, circles3d, intersectLinePlane, intersectLineSphere

   ---------
   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 18/02/2005.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function circle = intersectPlaneSphere(plane, sphere)
0002 %INTERSECTPLANESPHERE Return intersection circle between a plane and a sphere.
0003 %
0004 %   CIRC = intersectPlaneSphere(PLANE, SPHERE)
0005 %   Returns the circle which is the intersection of the given plane
0006 %   and sphere.
0007 %   PLANE  : [x0 y0 z0  dx1 dy1 dz1  dx2 dy2 dz2]
0008 %   SPHERE : [XS YS ZS  RS]
0009 %   CIRC   : [XC YC ZC  RC  THETA PHI PSI]
0010 %   [x0 y0 z0] is the origin of the plane, [dx1 dy1 dz1] and [dx2 dy2 dz2]
0011 %   are two direction vectors,
0012 %   [XS YS ZS] are coordinates of the sphere center, RS is the sphere
0013 %   radius,
0014 %   [XC YC ZC] are coordinates of the circle center, RC is the radius of
0015 %   the circle, [THETA PHI] is the normal of the plane containing the
0016 %   circle (THETA being the colatitude, and PHI the azimut), and PSI is a
0017 %   rotation angle around the normal (equal to zero in this function, but
0018 %   kept for compatibility with other functions). All angles are given in
0019 %   degrees.
0020 %
0021 %   See Also:
0022 %   planes3d, spheres, circles3d, intersectLinePlane, intersectLineSphere
0023 %
0024 %   ---------
0025 %   author : David Legland
0026 %   INRA - TPV URPOI - BIA IMASTE
0027 %   created the 18/02/2005.
0028 %
0029 
0030 %   HISTORY
0031 %   27/06/2007: change output format of circle, add support for multiple
0032 %       data
0033 %   2011-06-21 use degrees for angles
0034 
0035 % number of inputs of each type
0036 Ns = size(sphere, 1);
0037 Np = size(plane, 1);
0038 
0039 % unify data dimension
0040 if Ns ~= Np 
0041     if Ns == 1
0042         sphere = sphere(ones(Np, 1), :);
0043     elseif Np == 1
0044         plane = plane(ones(Ns, 1), :);
0045     else
0046         error('data should have same length, or one data should have length 1');
0047     end
0048 end
0049 % center of the spheres
0050 center  = sphere(:,1:3);
0051 
0052 % radius of spheres
0053 if size(sphere, 2) == 4
0054     Rs  = sphere(:,4);
0055 else
0056     % assume default radius equal to 1
0057     Rs  = ones(size(sphere, 1), 1);
0058 end
0059 
0060 % projection of sphere center on plane -> gives circle center
0061 circle0 = projPointOnPlane(center, plane);
0062 
0063 % radius of circles
0064 d   = distancePoints3d(center, circle0);
0065 Rc  = sqrt(Rs.*Rs - d.*d);
0066 
0067 % normal of planes = normal of circles
0068 nor = planeNormal(plane);
0069 
0070 % convert to angles
0071 [theta, phi] = cart2sph2(nor(:,1), nor(:,2), nor(:,3));
0072 psi = zeros(Np, 1);
0073 
0074 % create structure for circle
0075 k = 180 / pi;
0076 circle = [circle0 Rc [theta phi psi]*k];

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