From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: calculate the intersection of 3 sphere
Date: Mon, 26 Mar 2012 16:18:11 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <jkq4s3$44b$>
References: <jkpplu$li7$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1332778691 4235 (26 Mar 2012 16:18:11 GMT)
NNTP-Posting-Date: Mon, 26 Mar 2012 16:18:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:762245

"marcel " <> wrote in message <jkpplu$li7$>...
> I try to calculate the coordinate of two points of intersection 3-sphere, it is analytically complicated, so I asked whether it is possible to use subs in the solve function to pass parameters in the function? .....
- - - - - - - - -
  Yes, a single analytic expression would be quite complicated.  However, a sequence of mathematical operations can accomplish the same task with much less complexity.  I dug the following up which I wrote from an old CSSM thread which you might be interested in.  Even though this is matlab code, the operations expressed by it can be considered to express mathematically the analytic solution to your problem, though not in a single expression.  

  The thread is located at:
Date: Thu, 29 Jan 2009 00:19:02 +0000 (UTC)

The pertinent text is as follows:

  "Given three spheres, you want to find their two points of intersection (if they actually intersect.)  As you can see, it gives an answer without any iteration.  My claim is that the only time these calculations become subject to inaccuracy is when the problem is inherently ill-conditioned, as for example when the centers are nearly colinear, or when the two points of intersection are very close together.

  Let p1, p2, and p3 be three-element vectors giving the x,y,z coordinates of the spheres' three centers, and r1, r2, and r3 their respective radii.  Then do this:

 p21 = p2-p1;
 p31 = p3-p1;
 c = cross(p21,p31);
 c2 = sum(c.^2);
 u1 = cross(((sum(p21.^2)+r1^2-r2^2)*p31 - ...
 v = sqrt(r1^2-sum(u1.^2))*c/sqrt(c2);
 i1 = p1+u1+v;
 i2 = p1+u1-v;

The i1 and i2 will be vectors for the two points of intersection.  If there is any possibility of having radii such that no solution is possible (which can happen very easily) you should test that the first square root used in the calculation of v is real.  An impossible problem will make it imaginary."

Roger Stafford