Let (h,k) be the coordinates of the center of the circle, and r its radius. Then the equation of the circle is: (x-h)^2 + (y-k)^2 = r^2 Since the three points all lie on the circle, their coordinates will satisfy this equation. That gives you three equations: (x1-h)^2 + (y1-k)^2 = r^2 (x2-h)^2 + (y2-k)^2 = r^2 (x3-h)^2 + (y3-k)^2 = r^2 in the three unknowns h, k, and r. To solv
| 183 | By means of solving the matrix equation above, we get the circumcircle center point O. |
| 184 | */ |
| 185 | static Point2f circumcircle(const Point2f& A, const Point2f& B, const Point2f& C) |
| 186 | { |
| 187 | float AB_x = B.x - A.x, AC_x = C.x - A.x; |
| 188 | float AB_y = B.y - A.y, AC_y = C.y - A.y; |
| 189 | |
| 190 | // [ AB_x AB_y ] [ x ] = [ AB_x*AB_mx + AB_y*AB_my ] |
| 191 | // [ AC_x AC_y ] [ y ] = [ AC_x*AC_mx + AC_y*AC_my ] |
| 192 | |
| 193 | float denorm = AB_x * AC_y - AC_x * AB_y; |
| 194 | assert(std::abs(denorm) > std::numeric_limits<float>::epsilon()); |
| 195 | |
| 196 | float M_x = AB_x*(B.x + A.x)/2 + AB_y*(B.y + A.y)/2; |
| 197 | float M_y = AC_x*(C.x + A.x)/2 + AC_y*(C.y + A.y)/2; |
| 198 | |
| 199 | float x = (M_x*AC_y - M_y*AB_y)/denorm; |
| 200 | float y = (AB_x*M_y - AC_x*M_x)/denorm; |
| 201 | return Point2f(x, y); |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | Cubic interpolation http://www.paulinternet.nl/?page=bicubic |
no outgoing calls
no test coverage detected