Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Triangulation using sphere intersects
Date: Sat, 28 Jan 2012 04:05:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 25
Message-ID: <jfvs5m$lp4$1@newscl01ah.mathworks.com>
References: <gg5tb3$ms3$1@fred.mathworks.com> <jfu4k6$lav$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1327723510 22308 172.30.248.46 (28 Jan 2012 04:05:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 28 Jan 2012 04:05:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:756004

"satish sahu" <satishs@iitk.ac.in> wrote in message <jfu4k6$lav$1@newscl01ah.mathworks.com>...
>  I am satish sahu, a student in my thesis i have certain problem in which i have to find and get the plot of circle where two sphere are intersecting.
> have you developed any MATLAB code regarding this matter or could you tell me where can i find the code or u have any algorithm.
- - - - - - - - -
  Hello Satish Sahu.  I last communicated on this thread three years ago, so it has taken me a while to refresh my memory on this subject.  You wish to plot the circle of intersection between two given spheres.  The following will accomplish that in matlab code, and derives roughly from the "problem 1)" part of the outline I described in this thread 21 Nov. 2008.

  Let C1 = [x1,y1,z1] and C2 = [x2,y2,z2] be two row vectors defining the spheres' centers and r1 and r2 their respective radii.  Then do this:

 C21 = C2-C1;
 d2 = dot(C21,C21);
 C0 = (C1+C2)/2+(r1^2-r2^2)/(2*d2)*C21;
 R = sqrt(((r1+r2)^2-d2)*(d2-(r2-r1)^2)/(4*d2));
 N = null(C21).';
 T = linspace(0,2*pi).';
 V = bsxfun(@plus,C0,R*[cos(T),sin(T)]*N);

  The point C0 is the center of the intersection circle and R is its radius.  C0 lies along the line connecting the centers, C1 and C2.  The two rows of N, produced with matlab's 'null' function, are mutually orthogonal unit vectors which are also orthogonal to the vector C21 = C2-C1.  The column vectors V(:,1), V(:,2), and V(:,3) are the X, Y, and Z vectors you need to do a plot of the circle using 'plot3'.  They trace out the path of the circle around a full angle of 2*pi about C0.

  You can verify the accuracy of this code by checking that the distance from points on the circle are all a distance r1 from C1 and r2 from C2.  You can also check that vectors pointing from C0 to points on the circle are orthogonal to C2-C1 and are all of length R, which shows that C0 is indeed at the circle's center.

  In case your spheres don't intersect, that will result in taking the square root of a negative number in computing R, so you might want to put a test for that in the above code.

  Note that on plots of this circle with 'plot3' the circle may not appear orthogonal to the line between C1 and C2 unless you have set the plot scaling appropriately.

Roger Stafford