Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Curious
Posts:
2,221
Registered:
12/6/04


Re: Finding the centre of a circle
Posted:
Aug 28, 2014 10:24 AM


Christopher Creutzig <Christopher.Creutzig@mathworks.com> wrote in message <53FF3612.9060901@mathworks.com>... > On 8/28/14, 3:32 PM, ABID wrote: > > am currently trying to find the centre of a circle, where I have > > two points on the circumference and the radius > > any code or algorithm please.... > > That does not define the centre uniquely, but only up to reflection > about the line through the points. I hope you are ok with that. > > The algorithm is easy: > > Given P1 and P2 and radius r, > > 1. draw a circle c1 of radius r around P1, > 2. draw a circle c2 of radius r around P2. > 3. The intersection of c1 and c2 is the (zero, one, or two) points > satisfying the requirement. > > > That algorithm translates into a coordinate formula quite easily: > > >> syms x1 y1 x2 y2 r x y > >> [x0, y0] = solve((xx1)^2 + (yy1)^2 == r, ... > (xx2)^2 + (yy2)^2 == r, x, y); > >> pretty(simplify(x0)) > / x1 x2 y1 #1 y2 #1 \ >   +  +     >  2 2 2 2  >   >  x1 x2 y1 #1 y2 #1  >   +    +   > \ 2 2 2 2 / > > where > > / 2 2 2 2 \ >  x1  2 x1 x2 + x2 + y1  2 y1 y2 + y2  4 r  > #1 == sqrt    >  2 2 2 2  > \ x1  2 x1 x2 + x2 + y1  2 y1 y2 + y2 / > > > >> pretty(simplify(y0)) > / y1 y2 x1 #1 x2 #1 \ >   +    +   >  2 2 2 2  >   >  y1 y2 x1 #1 x2 #1  >   +  +     > \ 2 2 2 2 / > > where > > / 2 2 2 2 \ >  x1  2 x1 x2 + x2 + y1  2 y1 y2 + y2  4 r  > #1 == sqrt    >  2 2 2 2  > \ x1  2 x1 x2 + x2 + y1  2 y1 y2 + y2 / > > > Discard complex values ? if the sqrt is complex, you do not have such a > circle. > > > HTH, > > Christopher >
I agree that two points on the circumference and the radius do not uniquely define a circle.
Since the general equation for a circle with center (a, b) and radius r in the Cartesian coordinate system is (x  a)^2 + (y  b)^2=r^2, I think you need to use r^2 in place of r in:
> [x0, y0] = solve((xx1)^2 + (yy1)^2 == r, ... > (xx2)^2 + (yy2)^2 == r, x, y);
You have two equations with two unknowns, but it is a quadratic equation which will give more than one solution, i.e.:
(x1  a)^2 + (y1  b)^2=r^2 (x2  a)^2 + (y2  b)^2=r^2



