# Center of a Circle given 3 Coordinates.



## mu38&Bg# (Mar 20, 2009)

I had the opportunity yesterday to find the center of a circle on my CNC mill. I needed to center it without the aid of an indicator mostly because I don't have a way to mount the indicator into my milling head. I don't have a probe to touch off yet either, so I did it by hand. When I actually did the job, I drew the coordinates out in CAD, it was quick at the time. I figured there must be a way to calculate, and that would be much faster next time. Here is a link to an Excel file that does just this. The only catch is the none of the points can be on horizontal or vertical lines. So when you move your Y and Y axes to go to the next point, you must move both axes. Moving X or Y until you touch off the other side of the circle won't calculate. This is useful for CNC or simple DROs. Keep in mind that the Radius and Diameter are related to the probe center, not the diameter you are touching off.

Enjoy.

www.dieselrc.com/download/circlecenter.xls


----------



## mklotz (Mar 20, 2009)

Here's an online calculator for this problem

http://www.mortonfox.com/js/circ.htm

that permits two of the points to lie on the same line.


----------



## Mike N (Mar 20, 2009)

This is interesting! But I don't understand how you physically found the locations of the 3 points on your work piece, am I missing something?


----------



## mu38&Bg# (Mar 20, 2009)

mklotz  said:
			
		

> Here's an online calculator for this problem
> 
> http://www.mortonfox.com/js/circ.htm
> 
> that permits two of the points to lie on the same line.



Yep saw that one. My CNC mill PC isn't connected to the internet. And the math exercise was fun.

I just moved the axes slowly, .01mm increments to touch the tool to the edge of the circle, a bore in this case. When I touched, I recorded my coordinates. My X-Y table is electrically insulated from the milling head so I use an ohm meter to detect when I touch. The result was very good.

Oh well.


----------



## Jadecy (Mar 20, 2009)

You can also locate the center of a circle with a circle drawing compass.

1) set the compass to a distance large than the radius but less than the diameter. Try to guestimate it close to the radius but not under.

2) pick a point on the edge and draw an arch on the circle.

3) pick a point on the edge on the other side of the circle and draw an arch.

4) pick an arbitrary point approx. 90 degrees from the current point and repeat steps 2 & 3.

5) Use a straight edge to draw a line between the intersecting points of the archs drawn in steps 2 & 3.

6) The center is where the lines intersect. 

I know this may not work for your specific situation but thought it might be useful to someone.

I can't post a picture right now but will try to later. The written instructions are a little hard to follow.


----------



## mklotz (Mar 20, 2009)

Or to put it more simply...

Draw any two chords on the circle. Construct the perpendicular bisectors of these chords. Where they intersect is the center of the circle.


----------



## mu38&Bg# (Mar 20, 2009)

mklotz  said:
			
		

> Or to put it more simply...
> 
> Draw any two chords on the circle. Construct the perpendicular bisectors of these chords. Where they intersect is the center of the circle.



That's exactly what the Excel file calculates. But, when the slope of a line becomes zero, it throws a Div/0 error. I'll have to figure out a fix.


----------



## djc (Mar 22, 2009)

dieselpilot  said:
			
		

> ...when the slope of a line becomes zero, it throws a Div/0 error.



Easy fix is to use an IF statement to test the value of the difference between the values that you are dividing by.

IF (VALUE2 - VALUE1) < 1E-6 THEN SLOPE = 0.

Don't be tempted to test for equality to zero.

Your spreadsheet would be a lot easier to read and to debug if you use intermediate cells for intermediate calculations/values instead of putting one great long formula into one cell.


----------



## mklotz (Mar 22, 2009)

You won't have any division by zero problems if you use the equation for a circle and solve the three simultaneous equations. An outline of that technique is given here:

http://mathforum.org/library/drmath/view/55233.html


----------



## BobWarfield (Mar 22, 2009)

Those math problems are fun!

However, if you've got a PC driven CNC, I will assume you're using Mach3 (could be EMC). If so, you're trick with the ohmeter touchprobe is a hop skip and jump away from being able to completely automate the task you describe as well as many others.

See for example this article:

http://www.hossmachine.info/forum/yaf_postsm98_Automatic-Tool-Probe.aspx#98

All kinds of clever capabilities are built right into the Mach3 macros and screen set Hoss shows including edge finding, corner finding, and center of circles.

I plan to get my CNC set up to do this on the relatively near term as it looks really handy. As a by product, you can use it to set your tool heights as well.

Those of you not into CNC, my appologies. Move on, these are not the droids you're looking for!

Cheers,

BW


----------



## mklotz (Mar 23, 2009)

The CIRC3 archive on my webpage includes two programs related to this problem.

CIRC3 calculates the radius given the lengths of two distinct chords on the circular arc.
(This was written for a fellow who wanted to find the diameter of a large gear from a broken chunk.)

CIRC3C solves the subject problem of this thread via the intersection of the chord bisectors method. It can handle two points with the same x coordinate or two points with the same y coordinate.

Source code for both these programs is included in the distribution.

CIRC3C is a rather complex program requiring a number of functions and I realized that it could be seriously simplified by using the technique of simultaneously solving the three equations of a circle that can be constructed with the three points.

I'll not bother putting the simplified version up on my page but, for those who are familiar with C, I've posted below the function that does all the number crunching in the program.

===========================================================

/* circ3..----------------------------------------------------------------- */

/*
find the center and radius of a circle that passes through three points
using the equation of a circle
the center location is stored in (xc,yc) and the radius of the circle in r.

note that no error checking is done for the anomalous case in which the three
points are colinear.
*/

void circ3 (dbl x1, dbl y1, dbl x2, dbl y2, dbl x3, dbl y3,\
dbl *xc, dbl *yc, dbl *r)

{
dbl k,l,m,n,c,d,det;

k=x2-x1; l=y2-y1; c=0.5*(x2*x2-x1*x1+y2*y2-y1*y1);
m=x3-x2; n=y3-y2; d=0.5*(x3*x3-x2*x2+y3*y3-y2*y2);
det=k*n-m*l;

*xc=(n*c-l*d)/det;
*yc=(k*d-m*c)/det;


*r=RSS2((x1-*xc),(y1-*yc));
}


----------



## RonGinger (Mar 23, 2009)

The CopyCat wizard in Mach does this. Its a 'reverse engineering' program that lets you walk your way around a part picking up important points, like the start of a line segment, its end, start of an arc. Etc. For arcs you pickup the start, any point along the arc, then the end of the arc. The wizard then generates all the Gcode to run the part.

See http://www.machsupport.com/forum/index.php/topic,10437.0.html for a 'Kool' example of its use.


----------



## mu38&Bg# (Mar 24, 2009)

I've updated the file with a version that doesn't have any limitations. If it fails now, it is because the points fall on a straight line.

I should have checked here first.

http://en.wikipedia.org/wiki/Circumcircle

I use EMC2. It can be configured to find the center with a probe also. I just haven't added this to my mill yet.


----------



## mu38&Bg# (Mar 26, 2009)

I updated once again to add the probe diameter and calculate the feature diameter you are measuring.


----------

