Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Finding the centre of a circle
Replies: 4   Last Post: Aug 29, 2014 4:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 1,982
Registered: 12/6/04
Re: Finding the centre of a circle
Posted: Aug 28, 2014 10:24 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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((x-x1)^2 + (y-y1)^2 == r, ...

> (x-x2)^2 + (y-y2)^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((x-x1)^2 + (y-y1)^2 == r, ...
> (x-x2)^2 + (y-y2)^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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.