Finding center of a circle given two points and radius

Viewed 15866

I'm writing a G-Code interpreter and am having difficulties determining the center of a circle when given (X, Y) for two Points on the circle and the radius. I can plot a circle from 2 Points when given the center coint, but if a radius value is given instead, I can't use that to the a center point.

I've looked up multiple examples that are written in different forms of math (calculus, geometry, trig, etc.) but can't translate any of them to code. My understanding is that the values given generate two different center/intersecting points. Those are what I need to figure out.

The interpreter is running on an Arduino and written in C. If someone could just walk me through it in pseudo code even, I would be very grateful.

Thanks!

4 Answers

You can't necessarily always find a unique center point give two points and a radius. In fact there are three distinct cases:

        

Case 1:

                                  

happens when the given diameter is smaller than the distance between the given points. In this case there are no solutions.

Case 2:

                                  

happens when the given diameter is exactly equal ot the distance between two points. In this case there is a trivial solution of

                                  

Case 3:

happens when the given diameter is more than the distance between the two points. In this case there are two solutions from the equations:

                                  

which you can find solutions for example from this page:

                               

where q is the distance between the two points and [x3, y3] is the middle point.

   


Here in this Gist I'm trying to implement these in C, however not finished yet. feel free to continue from where I have left.

Related