Finding the Center of a circle given two points and a radius (algebraically)

Here's a completely different approach that might be easier to encode.

Your two given points ($(x_1, y_1)$ and $(x_2, y_2)$) and the centers of the two desired circles are at the four vertices of a rhombus with side length $r$. You can use the Pythagorean Theorem to find the length of the diagonal of the rhombus from $(x_1, y_1)$ to $(x_2, y_2)$. Better still, divide by two so you now have half the length of the diagonal. The two diagonals of a rhombus are perpendicular, so the point $(x_1, y_1)$, the center of the rhombus, and one of the circles' centers make a right triangle with hypotenuse $r$ and one leg equal to half the known diagonal. Use the Pythagorean Theorem to find half the length of the other diagonal.

Now you just need to construct line segments of that length with one end at the center of the rhombus, perpendicular to the known diagonal, and the other end of each segment will be the center of one of the desired circles.

That's the entire rationale of the procedure. For the detailed calculations, I'll assign names to various lengths as we go along in order to keep the equations from getting too ugly. (You'd probably want to do this anyway when you do this in software.)

enter image description here

Let $x_a = \frac12(x_2 - x_1)$ and $y_a = \frac12(y_2 - y_1)$; then the center of the rhombus is at $(x_0,y_0) = (x_1+x_a, y_1+y_a)$ and half the length of the known diagonal is $a = \sqrt{x_a^2 + y_a^2}.$ The length of the other diagonal is $b = \sqrt{r^2 - a^2}.$

Now suppose (for example) that $(x_0,y_0)$ is above and to the right of $(x_1,y_1)$ (assuming, at least for now, the usual mathematical Cartesian $x,y$ coordinates). To get from $(x_1,y_1)$ to $(x_0,y_0)$ along a straight line, we go to the right $x_a$ units and up $y_a$ units for every $a$ units of movement. So to get from $(x_0,y_0)$ to the center of one of the circles, $(x_3,y_3)$, we can just turn those rules $90$ degrees: we can go down $x_a$ units and to the right $y_a$ units for every $a$ units of movement; that is, $\frac{x_a}{a}$ down and $\frac{y_a}{a}$ right for each unit traveled along the diagonal. But the distance from $(x_0,y_0)$ to $(x_3,y_3)$ is $b$, so we will end up going down $b\frac{x_a}{a}$ units and to the right $b\frac{y_a}{a}$ units. In other words, \begin{align} x_3 &= x_0 + \frac{b y_a}{a}, \\ y_3 &= y_0 - \frac{b x_a}{a}. \\ \end{align} To get to the center of the other circle, $(x_4,y_4)$, we just go the same amount in the opposite direction from $(x_0,y_0)$: \begin{align} x_4 &= x_0 - \frac{b y_a}{a}, \\ y_4 &= y_0 + \frac{b x_a}{a}. \\ \end{align}

If $(x_0,y_0)$ is not above and to the right of $(x_1,y_1)$, or if you're working in a graphics coordinate system with $y$ downward, or both, the signs of either $x_a$ or $y_a$ (or both) might be negative instead of positive; but all the formulas above continue to work exactly the same way as before.

Tags:

Circles