INTERSECTLINESPHERE Return intersection points between a line and a sphere. PTS = intersectLineSphere(LINE, SPHERE); Returns the two points which are the intersection of the given line and sphere. LINE : [x0 y0 z0 dx dy dz] SPHERE : [xc yc zc R] PTS : [x1 y1 z1 ; x2 y2 z2] If there is no intersection between the line and the sphere, return a 2-by-3 array containing only NaN. Example % draw the intersection between a sphere and a collection of parallel % lines sphere = [50.12 50.23 50.34 40]; [x, y] = meshgrid(10:10:90, 10:10:90); n = numel(x); lines = [x(:) y(:) zeros(n,1) zeros(n,2) ones(n,1)]; figure; hold on; axis equal; axis([0 100 0 100 0 100]); view(3); drawSphere(sphere); drawLine3d(lines); pts = intersectLineSphere(lines, sphere); drawPoint3d(pts, 'rx'); % apply rotation on set of lines to check with non vertical lines rot = eulerAnglesToRotation3d(20, 30, 10); rot2 = recenterTransform3d(rot, [50 50 50]); lines2 = transformLine3d(lines, rot2); figure; hold on; axis equal; axis([0 100 0 100 0 100]); view(3); drawSphere(sphere); drawLine3d(lines2); pts2 = intersectLineSphere(lines2, sphere); drawPoint3d(pts, 'rx'); See also spheres, circles3d, intersectPlaneSphere
Package: matgeom