Prev: Re: [FT] [OT?] Has anyone considered... | Next: RE: [FT][computer] Has anyone considered... |

Date: Mon, 11 Sep 2000 10:33:49 +0100

Subject: Re: [FT] [computer] 3D math

```
"Barclay, Tom" wrote:
> Hiya
>
> I'm looking for a non-horrendous formula for calculating, given the
> following facts,
>
> - in 3 space
> - a sphere we shall call S1 located at coorinates (x1,y1,z1) of radius
r1.
> - a sphere we shall call S2 located at coorinates (x2,y2,z2) of radius
r2.
> - a point we shall call P3 located at coordinates (x3,y3,z3).
>
> A) Do r1 and r2 intersect one another? What formula will determine
this?
>
> <My guess: Take a line between the centre of S1 and S2 and determine
if the
> length of this segment exceeds the sum of the radii r1 and r2>.
Correct. Distance between the sphere centres (d) is equal to
d = sqrt ((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2)
If this distance is less than (r1 + r2) then the spheres intersect.
If you want a faster version then don't perform the square root
calculation on
d. Instead, square (r1 + r2) so that your comparison is
d^2 < (r1 + r2)^2
This is a trick I use a lot of the time so save unnecessary square root
calls
(which are very computationally expensive).
> B) Is point P3 within sphere S1?
>
> <My guess here is take the magnitude of the line between the centre of
S1
> and P3 and if it is <= radius r1 then P3 is inside of S1>.
>
Correct again, but you can use the same trick as above by not finding
the root
of the line between S1 and P3.
Tony
```

Prev: Re: [FT] [OT?] Has anyone considered... | Next: RE: [FT][computer] Has anyone considered... |