【解题报告】已知三角形的顶点坐标为(xx1,yy1),(xx2,yy2)和(xx3,yy3),要求外接圆圆心坐标(x,y),有圆心O到三个顶点A,B,C距离相等,可得两个方程,联立求解这两个方程,即可得外接圆圆心坐标,而根据已经求得的圆心坐标和向量旋转公式就可以求出正多边形其它顶点的坐标,将向量OA逆时针旋转t角度的向量OB,则向量旋转公式为:(B点坐标为(xx,yy),A点坐标为(xx1,yy1),O为圆心)
xx=(xx1-x)*cos(t)-(yy1-y)*sin(t)+x; yy=(xx1-x)*sin(t)+(yy1-y)*cos(t)+y
对于n边形来说,t=2*PI/n,依次将向量OA旋转t,2t,……(n-1)t,就可求得其它所有顶点的坐标,在求解每个顶点坐标的过程当中,记录这n个顶点中X坐标的最大值maxx和最小值minx,以及y坐标的最大值maxy和最小值miny,则求矩形面积为:(maxx-minx)*(maxy-miny).
struct point { double x; double y; } a, b, c; double Distance(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } point circle_center(point a, point b, point c) { double tmp = (c.x * c.x - b.x * b.x) * (b.y - a.y); tmp += (b.y * b.y - a.y * a.y) * (b.y - c.y); tmp -= (a.x * a.x - b.x * b.x) * (b.y - c.y); tmp -= (b.y * b.y - c.y * c.y) * (b.y - a.y); tmp /= 2 * ((c.x - b.x) * (b.y - a.y) - (a.x - b.x) * (b.y - c.y)); point ret; ret.x = tmp; ret.y = ((2 * ret.x - b.x - a.x) * (a.x - b.x) / (b.y - a.y) + a.y + b.y) / 2; return ret; } double get_rectangle(point a, point C, int n)//旋转圆心和一个顶点的向量,得到其余点,找到上下左右边界点 { double angle = 2 * MY_PI / n; double minx, maxx, miny, maxy; minx = miny = 10000000000.0; maxx = maxy = -10000000000.0; int i; for (i = 0; i < n; ++i) { double tmpx = (a.x - C.x) * cos(i * angle) - (a.y - C.y) * sin(i * angle) + C.x; double tmpy = (a.x - C.x) * sin(i * angle) - (a.y - C.y) * cos(i * angle) + C.y; if (tmpx < minx) minx = tmpx; if (tmpx > maxx) maxx = tmpx; if (tmpy < miny) miny = tmpy; if (tmpy > maxy) maxy = tmpy; } return (maxx - minx) * (maxy - miny); } int main() { int n; int cases = 1; while (scanf("%d", &n) == 1 && n) { scanf("%lf%lf%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y, &c.x, &c.y); point C = circle_center(a, b, c); printf("Polygon %d: %.3lf\n", cases++, get_rectangle(a, C, n)); } return 0; }