Path: news.mathworks.com!not-for-mail
From: "Todd " <towatsonextracharacters@itwtech.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: calculate the intersection of 3 sphere
Date: Thu, 23 Aug 2012 20:32:07 +0000 (UTC)
Organization: ITW Tech Ctr
Lines: 31
Message-ID: <k16407$ea0$1@newscl01ah.mathworks.com>
References: <jkpplu$li7$1@newscl01ah.mathworks.com> <jkq4s3$44b$1@newscl01ah.mathworks.com>
Reply-To: "Todd " <towatsonextracharacters@itwtech.com>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1345753927 14656 172.30.248.48 (23 Aug 2012 20:32:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 23 Aug 2012 20:32:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11388
Xref: news.mathworks.com comp.soft-sys.matlab:777113

Hey Roger,

Thank you for the help you've provided in this thread so far. It has been very helpful to me. 

In your last sentence, "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."

What would be your suggestion as to how to deal with such a scenario? As you mention, it does crop up rather often and it's a huge part of my project. 

Any help would be appreciated.
Best,
Yash

> 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 - ...
>              (sum(p31.^2)+r1^2-r3^2)*p21)/2,c)/c2;
>  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