Get the equation of a circle through the points $(1,1), (2,4), (5,3) $.
I can solve this by simply drawing it, but is there a way of solving it (easily) without having to draw?
Get the equation of a circle through the points $(1,1), (2,4), (5,3) $.
I can solve this by simply drawing it, but is there a way of solving it (easily) without having to draw?
On
Consider the general (implicit) equation that defines a circle, with parameters $\alpha$, $\beta$, $\gamma$. Substitute the coordinate of the given points and get three linear equations in the three variables $\alpha$, $\beta$, $\gamma$. Solve the system.
On
Big hint:
Let $A\equiv (1,1)$,$B\equiv (2,4)$ and $C\equiv (5,3)$.
We know that the perpendicular bisectors of the three sides of a triangle are concurrent.Join $A$ and $B$ and also $B$ and $C$.
The perpendicular bisector of $AB$ must pass through the point $(\frac{1+2}{2},\frac{1+4}{2})$
Now find the equations of the straight lines AB and BC and after that the equation of the perpendicular bisectors of $AB$ and $BC$.Solve for the equations of the perpendicular bisectors of $AB$ and $BC$ to get the centre of your circle.
On
You can also find first $R$ from the sin Law:
$$R= \frac{BC}{2 \sin (A)}= \frac{BC \cdot AB \cdot AC }{2 \| AB \times AC \|} \tag{$*$}$$
Next, write the equations of circles of radius $R$ with centre $A$ and $B$ and solve.
Note The formula $(*)$ is the well known geometric formula for the area of a triangle:
$$\mbox{Area}= \frac{abc}{4R} \,.$$
On
As a programmer this was the best solution for me as there is no division by zero:
For given (x1,y1) , (x2,y2) and (x3,y3) first form A,B,C and D:
$$A=x_1(y_2-y_3) - y_1(x_2-x_3)+x_2y_3 -x_3y_2$$ $$B=(x_1^2 + y_1^2)(y_3-y_2)+(x_2^2+y_2^2)(y_1-y_3)+(x_3^2+y_3^2)(y_2-y_1)$$ $$C=(x_1^2+y_1^2)(x_2-x_3)+(x_2^2+y_2^2)(x_3-x_1)+(x_3^2+y_3^2)(x_1-x_2)$$ $$D=({x_1^2}+{y_1^2})({x_3}{y_2} - {x_2}{y_3})+(x_2^2 + y_2^2)(x_1y_3-x_3y_1)+(x_3^2+y_3^2)(x_2y_1 - x_1y_2)$$
If A=0 then the points are colinear elasewhere using A,B,C you can find center and radius of circle:
$$x_c=-B/2A$$ $$y_c=-C/2A$$
$$R= \sqrt {\frac {B^2+C^2-4AD}{4A^2}}$$
Finally the formula of the circle is:
$$(x-x_c)^2+(y-y_c)^2=R^2$$
On
I just wanted to flag Scott's answer to this question which is very concise and is probably faster than the matrix-based version. I've included below a C++17 implementation of the complex arithmetic solution to the problem
#include <complex>
#include <optional>
#include <iostream>
struct point {
double x;
double y;
};
struct circle {
double x;
double y;
double r;
};
std::optional<circle> circle_through_three_points(const point& pt1, const point& pt2, const point& pt3) {
using namespace std::complex_literals;
auto pt_to_z = [](const point& pt)->std::complex<double> { return { pt.x,pt.y }; };
auto z1 = pt_to_z(pt1), z2 = pt_to_z(pt2), z3 = pt_to_z(pt3);
auto w = (z3 - z1) / (z2 - z1);
if (w.imag() == 0)
return std::nullopt; // the three points are collinear
auto magnitude_w = std::abs(w);
auto c = (z2 - z1) * (w - magnitude_w * magnitude_w) / (2i * w.imag()) + z1;
auto r = std::abs(z1 - c);
return circle{ c.real(), c.imag(), r };
}
int main()
{
auto c1 = circle_through_three_points({ 1,1 }, { 2,4 }, { 5,3 });
auto c2 = circle_through_three_points({ 1,1 }, { 2,2 }, { 3,3 });
if (c1)
std::cout << "circle 1 is (" << c1->x << "," << c1->y << "," << c1->r << ")\n";
else
std::cout << "circle 1 is degenerate\n";
if (c2)
std::cout << "circle 2 is (" << c2->x << "," << c2->y << "," << c2->r << ")\n";
else
std::cout << "circle 2 is degenerate\n";
}
On
It must be unlucky to add a 13th answer to an 8-year-old question that has been viewed 131,000 times (I don't know why it appeared on the front page today), but I just have to point out that this particular example can be solved by a simple mental calculation.
If $A = (1,1),$ $B = (2,4)$ and $C = (5,3),$ then - making $B$ the "origin", to see if it helps (I tried $A$ first, and would have tried $C$ next, if $B$ hadn't worked) - we have $A - B = (-1, -3)$ and $C - B = (3, - 1),$ whence $(A - B) \cdot (C - B) = -3 + 3 = 0,$ i.e., the angle at $B$ is a right angle, therefore $AC$ is a diameter, therefore the centre is $(A + C)/2 = (3, 2),$ and a radius vector is $(2, 1),$ therefore the square of the radius is $5,$ therefore the equation is $(x -3)^2 + (y - 2)^2 = 25.$
Presumably the values of $A, B, C$ were chosen to enable this simple solution.
I'll get me coat. :)
On
This solves your problem in python...
def three_point_circle(z1,z2,z3):
a = 1j*(z1-z2)
b = 1j*(z3-z2)
m1 = a.imag/a.real
c = (z1-z2)/2
p1 = z2+c
b1 = p1.imag-m1*p1.real
m2 = b.imag/b.real
d = (z3-z2)/2
p2 = z2+d
b2 = p2.imag-m2*p2.real
x = (b2-b1)/(m1-m2)
y = (m2*b1-m1*b2)/(m2-m1)
center = x+1j*y
radius = abs(center-z1)
return x,y,radius
as long as there is not division by zero.
If there is division by zero, you can solve this by revolving your input numbers (multiply by some random power of the imaginary unit 1j) and then revolve the x,y coordinates back (set to a complex number and multiply by 1j to the negative power you used).
On
(Rephrasing Scott's answer.) Let the three points be $z_1$, $z_2$, $z_3$ as complex numbers. These lie on a circle $C_{old}$ given by $|z-c|^2=r^2$. We can map $C_{old}$ to another circle $C_{new}$ given by $|w-d|^2=s^2$ that is easier to work with using a linear transformation $f(z)=w=az+b$. In other words we'll have $f(C_{old})=C_{new}$ and moreover $f(c)=d$, the center of $C_{old}$ gets mapped by $f$ to the center of $C_{new}$. This should be intuitively clear since the linear transformation translates/scales/rotates $C_{old}$.
One choice of linear map is $f(z)=\frac{z-z_1}{z_2-z_1}$, with $f(z_1)=w_1=0$, $f(z_2)=w_2=1$. Evaluating the defining equation for $C_{new}$ at $w_1=0$, $w_2=1$, $w_3=f(z_3)$ gives \begin{align*} |d|^2&=s^2=d\bar{d},\\ |1-d|^2&=s^2=1-d-\bar{d}+|d|^2,\\ |w_3-d|^2&=s^2=|w_3|^2-w_3\bar{d}-\bar{w}_3d+|d|^2. \end{align*} Simplifying some gives the system of linear equations (in $d$, $\bar{d}$) \begin{align*} d+\bar{d}&=1\\ \bar{w}_3d+w_3\bar{d}&=|w_3|^2. \end{align*} Solving for $d$ gives the center of $C_{new}$ (assuming $w_3\neq\bar{w}_3$) $$ d=\frac{w_3-|w_3|^2}{w_3-\bar{w}_3}, $$ and applying $f^{-1}(w)=(z_2-z_1)w+z_1$ gives the center of $C_{old}$ $$ c=f^{-1}(d)=z_1+(z_2-z_1)d. $$
[Remark: If $w_3=\bar{w}_3$, then $z_3-z_1=w_3(z_2-z_1)$ for the real scalar $w_3$, so that $z_3$ is on the line through $z_1$ and $z_2$.]
Finally, the radius of $C_{old}$ can be found by evaluating $|z_i-c|^2=r^2$ at any of the initial three points.
Here is yet another implementation (Python):
def center_radius(z1, z2, z3):
"""
Return (center, radius), with complex center, of the circle through
complex z1, z2, z3. If z1, z2, z3 are colinear, print "colinear" and
return None.
"""
if z1 == z2:
print("colinear")
return None
def f(z):
return (z-z1)/(z2-z1)
def f_inv(w):
return z1+(z2-z1)*w
w3 = f(z3)
if w3.imag == 0: #may want abs(w3.imag) < eps
print("colinear")
return None
d = (w3-w3*w3.conjugate())/(w3-w3.conjugate())
c = f_inv(d)
r = abs(z1-c)
return (c, r)
For example,
>>> center_radius(0,1,complex(0,1))
((0.5+0.5j), 0.7071067811865476)
On
Just for the sake of adding an answer:
Take any two points of the given three :$A(x_1,y_1)$ and $B(x_2,y_2)$. We will first determine the circle $\Omega$ having $AB$ as the diameter. This may seem arbitrary, but I assure you it is not.
Let $P(x,y)$ be any point on the circle. Then, $\angle APB$ is an angle in a semicircle and is hence a right angle. By writing $m_{AP}\cdot m_{BP}=-1$, we have $$\left(\frac{y-y_1}{x-x_1}\right)\left(\frac{y-y_2}{x-x_2}\right)=-1$$$$\implies (y-y_1)(y-y_2)+(x-x_1)(x-x_2)=0$$ is the equation of $\Omega$. Now, the straight line, $L$, through $A$ and $B$ is $$\frac{y-y_1}{x-x_1}= \frac{y_2-y_1}{x_2-x_1}$$$$\implies (y-y_1)(x_2-x_1)-(x-x_1)(y_2-y_1)=0$$
Now we will write the equation of a family of circles passing through $A$ and $B$. This can be written as $$\Omega +\lambda L=0$$ and this can be verified to being a circle for all $\lambda$. Now you can understand why we found the equation of $\Omega$: to find a similar (to the required curve) but special curve passing through the points of interest.
Now, put $(x_3,y_3)$ in the equation and solve for $\lambda$. This will give the required equation of the circle.
Follow these steps: