Description
There is a polygon A1A2…An (the vertices Ai are numbered in the clockwise order). On each side AiAi+1 an isosceles triangle AiMiAi+1 is built on the outer side of the polygon, and angle AiMiAi+1 = αi. Here An+1 = A1.
The set of angles ai satisfies a condition that the sum of angles in any of its nonempty subsets is not aliquot to 360 degrees.
You are given n <= 50, co-ordinates of vertices Mi and angles αi (measured in degrees). Write a program which restores co-ordinates of the polygon vertices.
Input
The first line of an input contains an integer n. The next n lines contain pairs of real numbers which are co-ordinates of points Mi. And the last n lines of the file consist of degree values of angles αi.
Output
The output file should contain n lines of pairs of coordinates of the points
Sample Input
3
0 2
3 3
2 0
90
90
90
Sample Output
1 1
1 3
3 1
只要多边形的一个点就可以求出所有的点
随便初始一个点P,在这个点周围找一个点A为可能的点
依次旋转算出P[1],P[2]…P[n]
若P[n]==A找到
否则若distance(A,P[n])<distance(P,P[n]),令P=A
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
int sgn(double x){return fabs(x)<eps?0:x<0?-1:1;}
double hypot(double x,double y){return sqrt(x*x+y*y);}
int n;
double ang[64];
struct Point{
double x,y;
Point(double x=0,double y=0):x(x),y(y){}
Point operator -(const Point &t){return Point(x-t.x,y-t.y);}
Point rotate(double rad){//rad为弧度 逆时针旋转
Point A=(*this);
double c=cos(rad),s=sin(rad);
return Point(A.x*c-A.y*s,A.x*s+A.y*c);
}
Point rotate(Point p,double angle){//绕p逆时针旋转后点
Point v=((*this)-p).rotate(angle);
return Point(p.x+v.x,p.y+v.y);
}
double distance(Point b){return hypot(x-b.x,y-b.y);}
}T[105],A,P;
int f[8][2]={1,0,1,1,1,-1,0,1,0,-1,-1,0,-1,1,-1,-1};
int Trans(){//模拟退火
for(int i=0;i<8;++i){
A=Point(P.x+f[i][0],P.y+f[i][1]);
Point tp=A;
for(int k=0;k<n;++k)tp=tp.rotate(T[k],ang[k]);
if(!sgn(A.distance(tp)))return P=A,1;
if(sgn(A.distance(tp)-P.distance(tp))<0)P=A;
}
return 0;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;++i)scanf("%lf%lf",&T[i].x,&T[i].y);
for(int i=0;i<n;++i)scanf("%lf",&ang[i]),ang[i]*=pi/180.0;
P=Point(0,0);
while(!Trans());
printf("%.lf %.lf\n",P.x,P.y);
for(int i=0;i+1<n;++i){
P=P.rotate(T[i],ang[i]);
printf("%.lf %.lf\n",P.x,P.y);
}
return 0;
}