Sign in to follow this  

centre point of a circle given three points

This topic is 4040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need help to calculate the centre point of a circle given three points around the circumference of the circle. (x1,y1),(x2,y2),(x3,y3) I know you have to find the equation of the perpendicular bisector of (x1,y1) to (x2,y2), you know that it passes through the midpoint of the segment: ((x1+x2)/2,(y1+y2)/2), and if the slope of the line connecting (x1,y1) to (x2,y2) is m, the slope of the perpendicular bisector is -1/m. its Working out the equations for the two lines, and finding their intersection, to get the coordinates of the center. Its the algorithm for this (e.g how to implement the code for) that I am not sure of. The first bit is simple addition and division. thanks for looking

Share this post


Link to post
Share on other sites
How about this - the distance from the center is the same for all points on the circumference.

So you've got 2 variables (Cx,Cy), and 3 equations:

||C-P1|| == ||C-P2||
||C-P1|| == ||C-P3||
||C-P2|| == ||C-P3||

This should be enough to figure out the variables.

Also you should take the distSQ to get rid of the sqrt and it could be done for 3D too since you have 3 equations.

Share this post


Link to post
Share on other sites
C code would look something like this:



//
// | x1 + x2 | | y2 - y1 | | xc |
// 1/2 | | + s | | = | |
// | y1 + y2 | | x1 - x2 | | yc |
//



double s = 0.5*((x2 - x3)*(x1 - x3) - (y2 - y3)*(y3 - y1));
double sUnder = (x1 - x2)*(y3 - y1) - (y2 - y1)*(x1 - x3);

if(sUnder == 0)
return 0; //insufficient data to calculate center

s /= sUnder;

double xc = 0.5*(x1 + x2) + s*(y2 - y1); // center x coordinate
double yc = 0.5*(y1 + y2) + s*(x1 - x2); // center y coordinate



This should work, if I didnt do any mistakes. Maybe there are some ways to optimize it some though.

Share this post


Link to post
Share on other sites
When I put in those values I get (414, 326) as the center, which is correct. I made a little win32 app to check it, here is the code:


case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);

double x1 = 50;
double y1 = 50;

double x2 = 400;
double y2 = 10;

double x3 = 250;
double y3 = 500;

mark(hdc, (int)x1, (int)y1, 0x000000ff);
mark(hdc, (int)x2, (int)y2, 0x0000ff00);
mark(hdc, (int)x3, (int)y3, 0x00ff0000);

double s = 0.5*((x2 - x3)*(x1 - x3) - (y2 - y3)*(y3 - y1));
double sUnder = (x1 - x2)*(y3 - y1) - (y2 - y1)*(x1 - x3);

if(sUnder != 0)
{
s /= sUnder;

double xc = 0.5*(x1 + x2) + s*(y2 - y1); // center x coordinate
double yc = 0.5*(y1 + y2) + s*(x1 - x2); // center y coordinate

mark(hdc, (int)xc, (int)yc, 0x00000000);
}

EndPaint(hWnd, &ps);
}
break;




Since you got a really big number, so I tink maybe you forgot to divide by sUnder.

Share this post


Link to post
Share on other sites

This topic is 4040 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this