Finding a point on a circle in 3D space which is a given distance away from another point

analytic geometrycirclesgeometryspherestrigonometry

I am trying to find a point, lets call it $X = (x_1, x_2, x_3)$, on a circle in 3D space (with a center $C_1$, radius $r$ and unit vector $\vec{AX}$ perpendicular to the plane of that circle ) which is a given distance $d$ away from another point $C_2$.

Parameters of the circle:

Center: $C_1 = (-0.0318, 0.2353, 0.4573)$

Radius: $r = 0.04$

Cicle Axis vector: $\vec{AX} = (-0.0026, 0.0259, 0.0259)$;

Point $C_2 = (-0.1501, 0.1470, 0.5339)$

Distance $d = 0.165$

The point I am interested in finding is $X = (-0.0085, 0.2134, 0.4815)$.

I have managed to find this by expressing the circle in this form: $A\sin(x) + B\cos(x) – r^2 = 0$, then using a solver in MATLAB to find where the distance between $C_2$ and $X$ is equal to $d$. This gives me one solution every time but also depends on the initial guess since there are 2 possible solutions. This method is also slow and I would like to solve this algebraically to improve the speed of calculations.

I was thinking that this could be solved by finding 2 intersection points between the circle and a sphere around $C_2$ with a radius $d$, but I am not sure if it's possible to solve that?

Best Regards,

Titas

Best Answer

As you say, this problem is essentially one of finding the intersections between a circle and sphere. One way to approach this is to parameterize the circle as $C_1+r(\vec u\cos t+\vec v\sin t)$, where $\vec u$ and $\vec v$ are a pair of orthogonal unit vectors in the plane of the circle. Finding the intersection is then a matter of solving $\|C_1+r(\vec u\cos t+\vec v\sin t)-C_2\|=d$ for $t$.

This is a messy trigonometric equation, though, so a simpler approach is to open up the problem a bit first: The points of intersection must obviously lie in the circle’s plane, but they must also be in the plane in which the sphere around $C_2$ intersects the sphere of radius $r$ around $C_1$. An equation for this plane can be found by subtracting the two sphere equations, and its intersection with the circle’s plane will be a line. If you parameterize this line in the usual way as $P_0+t\vec v$, finding the circle-sphere intersection points then reduces to solving a quadratic equation in $t$.

Using your example, equations of the two spheres are $$(x+0.0318)^2+(y-0.2353)^2+(z-0.4573)^2=0.04^2 \\ (x+0.1501)^2+(y-0.2134)^2+(z-0.4815)^2=0.165^2.$$ Subtracting the first from the second gives an equation of the two-sphere intersection plane: $$0.2366 x + 0.1766 y - 0.1532 z + 0.03806 = 0$$ and, using the point-normal form of a plane equation, the circle’s plane is given by $$-0.0026 x + 0.0259 y + 0.0259 z = 0.01802.$$ Their intersection is the line $$(0,0.2078,0.4880)+t(1,-0.6708, 0.7712).$$ Using the distance to $C_2$, we then solve the equation $$0.02833 + 0.1478 t + 2.045 t^2 = 0.165^2$$ to get $t=-0.06380$ and $t=-0.008505$, which yields the intersection points $(-0.06380, 0.2506, 0.4388)$ and $(-0.008505, 0.2135, 0.4814)$.


Addendum: The intersection points can be computed directly, without having to solve any equations explicitly. The direction of the above line can be found via cross product: $(C2-C1)\times AX$. Normalize this to get a unit direction vector $\vec u$. Passing to homogeneous coordinates, we have the two sphere centers $\tilde C_1 = (x_1,y_1,z_1,1)^T$ and $\tilde C_2 = (x_2,y_2,z_2,1)^T$. The plane of their intersection is $$\Pi = (2(x_2-x_1),2(y_2-y_1),2(z_2-z_1),(x_1^2+y_1^2+z_1^2-r^2)-(x_2^2+y_2^2+z_2^2-d^2))^T$$ and the intersection of the line through the two centers and this plane is $$\tilde P = (\tilde C_1^T\Pi)\tilde C_2-(\tilde C_2^T\Pi)\tilde C_1.$$ This is the midpoint of the intersection points you seek. Dehomogenize to get the Cartesian coordinates $P$ of this point and set $$\lambda = \sqrt{r^2-\|P-C_1\|^2} = \sqrt{d^2-\|P-C_2\|^2}.$$ The intersection points are then $P\pm\lambda\vec u$.

Alternatively, the distance from $C_1$ to $P$ is $$\Delta = {\|C_2-C_1\|^2+r^2-d^2\over2\|C_2-C_1\|}$$ (derivable via a straightforward application of the Pythagorean theorem) therefore $$P=C_1+\frac\Delta{\|C_2-C_1\|}(C_2-C_1) = \left(1-\frac\Delta{\|C_2-C_1\|}\right)C_1+\frac\Delta{\|C_2-C_1\|}C_2.$$ If you go this route, then you have $\lambda = \sqrt{r^2-\Delta^2}$.