TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)

描述

The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located at vertices of regular polygons. The moving sand dunes of the desert render the excavations difficult and thus once three vertices of a polygon are discovered there is a need to cover the entire polygon with protective fabric.

输入

Input contains multiple cases. Each case describes one polygon. It starts with an integer n <= 50, the number of vertices in the polygon, followed by three pairs of real numbers giving the x and y coordinates of three vertices of the polygon. The numbers are separated by whitespace. The input ends with a n equal 0, this case should not be processed.

输出

For each line of input, output one line in the format shown below, giving the smallest area of a rectangle which can cover all the vertices of the polygon and whose sides are parallel to the x and y axes.

样例输入

4
10.00000 0.00000
0.00000 -10.00000
-10.00000 0.00000
6
22.23086 0.42320
-4.87328 11.92822
1.76914 27.57680
23
156.71567 -13.63236
139.03195 -22.04236
137.96925 -11.70517
0

样例输出

Polygon 1: 400.000
Polygon 2: 1056.172
Polygon 3: 397.673

题意

已知正n边形三点求最小矩形覆盖面积

题解

正n边形上三点,求出正n边形上唯一外接圆

顺时针绕圆心旋转圆心角得到每个顶点的坐标

然后答案就是(最大的x-最小的x)*(最大的y-最小的y)

代码

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 struct Point
 5 {
 6     double x,y;
 7     Point(double x=0,double y=0):x(x),y(y){}
 8 };
 9 Point tcircle(Point pt1,Point pt2,Point pt3,double &radius)
10 { 
11     double x1=pt1.x,x2=pt2.x,x3=pt3.x;
12     double y1=pt1.y,y2 =pt2.y,y3=pt3.y;
13     double a=x1-x2,b=y1-y2,c=x1-x3,d=y1-y3;
14     double e=((x1*x1-x2*x2)+(y1*y1-y2*y2))/2.0;
15     double f=((x1*x1-x3*x3)+(y1*y1-y3*y3))/2.0;
16     double det=b*c-a*d;
17     double x0=(b*f-d*e)/det;
18     double y0=(c*e-a*f)/det;
19     radius=hypot(x1-x0,y1-y0);
20     return Point(x0,y0);
21 }
22 Point rotateShun(Point p,Point dx,double selt)
23 {
24     double xx=(p.x-dx.x)*cos(-selt)-(p.y-dx.y)*sin(-selt)+dx.x;
25     double yy=(p.x-dx.x)*sin(-selt)+(p.y-dx.y)*cos(-selt)+dx.y;
26     return Point(xx,yy);
27 }
28 Point p[55];
29 int main()
30 {
31     int n,ca=1;
32     double PI=acos(-1);
33     while(scanf("%d",&n),n)
34     {
35         for(int i=1;i<=3;i++)
36             scanf("%lf%lf",&p[i].x,&p[i].y);
37         double r=0.;
38         Point cir=tcircle(p[1],p[2],p[3],r);
39         double selt=2.*PI/n;
40         double maxx=p[1].x,minx=p[1].x,maxy=p[1].y,miny=p[1].y;
41         for(int i=2;i<=n;i++)
42         {
43             p[i]=rotateShun(p[i-1],cir,selt);
44             maxx=max(maxx,p[i].x);
45             minx=min(minx,p[i].x);
46             maxy=max(maxy,p[i].y);
47             miny=min(miny,p[i].y);
48         }
49         double ans=(maxx-minx)*(maxy-miny);
50         printf("Polygon %d: %.3f\n",ca++,ans);
51     }
52     return 0;
53 }

转载于:https://www.cnblogs.com/taozi1115402474/p/10294276.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值