# torus intersection

Here is problem. I have one torus defined in space by coordinates $(x, y, z)$ and it can be rotated in any direction. You can imagine it as torus total free in space. Torus is defined by two radius $(R, r)$ as well. This torus is ring torus. For example: location $(10, 10, 10)$ rotation $(20^\circ, 20^\circ, 20^\circ)$ $R=50$, $r=1$

1) How to test is given point $M(x, y)$ is inside that torus?

2) If I have another torus with same $(R, r)$ and it has two points that belong to both torus how I can calculate $x$, $y$, $z$ and rotation in space for the second torus? (I have all information for first torus and coordinates for two points)

3) This is a variation of the second question. If I have two tori with same $(R, r)$ and $x$, $y$, $z$ and rotations in space, how do I calculate intersection points (one or two points that is located on surface and belong to both torus - like on image). Of course if those points exist for given conditions.

The simplest answer is better. I need it for software.

Thanks!

-
There are at least two ways to specify a ring torus: give the tube radius and the distance from the center of the torus to the center of the tube, or give the inner and outer radii. Which one are you using? – J. M. Jul 23 '11 at 20:11
As for the third one: two non-tangent tori will intersect in a curve as opposed to a single point. Looking at it another way, you have two equations and three unknowns... – J. M. Jul 23 '11 at 20:13

On your question 1): As explained at How to find the center of an ellipse?, the best way to solve this sort of problem is to transform not the torus, which is cumbersome, but the point, which is relatively easy. So apply the inverse translation and then the inverse rotation to the point you want to test, and then see whether the resulting point $(x,y,z)$ lies in the unrotated, untranslated torus. Assuming the central circle of that torus has radius $R$, lies in the $x$-$y$-plane and is centred at the origin, the point on the central circle that's nearest to your point is
$$\left(\frac x{x^2+y^2}R,\frac y{x^2+y^2}R,0\right)\;.$$
Take the distance from your point to that point; your point lies in the torus if that distance is $\le r$.