void Game::GetCircle(Vertex v1, Vertex v2, Vertex v3, int &outx, int &outy, int &outr) { float eps = 1.192092896e-07F; Vertex m_Center; float x0 = v1.x; float y0 = v1.y; float x1 = v2.x; float y1 = v2.y; float x2 = v3.x; float y2 = v3.y; float y10 = y1 - y0; float y21 = y2 - y1; bool b21zero = y21 > -eps && y21 < eps; if (y10 > -eps && y10 < eps) { if (b21zero) // All three vertices are on one horizontal line. { if (x1 > x0) { if (x2 > x1) x1 = x2; } else { if (x2 < x0) x0 = x2; } m_Center.x = (x0 + x1) * .5F; m_Center.y = y0; } else // m_Vertices[0] and m_Vertices[1] are on one horizontal line. { float m1 = - (x2 - x1) / y21; float mx1 = (x1 + x2) * .5F; float my1 = (y1 + y2) * .5F; m_Center.x = (x0 + x1) * .5F; m_Center.y = m1 * (m_Center.x - mx1) + my1; } } else if (b21zero) // m_Vertices[1] and m_Vertices[2] are on one horizontal line. { float m0 = - (x1 - x0) / y10; float mx0 = (x0 + x1) * .5F; float my0 = (y0 + y1) * .5F; m_Center.x = (x1 + x2) * .5F; m_Center.y = m0 * (m_Center.x - mx0) + my0; } else // 'Common' cases, no multiple vertices are on one horizontal line. { float m0 = - (x1 - x0) / y10; float m1 = - (x2 - x1) / y21; float mx0 = (x0 + x1) * .5F; float my0 = (y0 + y1) * .5F; float mx1 = (x1 + x2) * .5F; float my1 = (y1 + y2) * .5F; m_Center.x = (m0 * mx0 - m1 * mx1 + my1 - my0) / (m0 - m1); m_Center.y = m0 * (m_Center.x - mx0) + my0; } float dx = x0 - m_Center.x; float dy = y0 - m_Center.y; float m_R = (float) sqrt(dx * dx + dy * dy); // the proper radius outx = m_Center.x; outy = m_Center.y; outr = m_R; }