公式如下,(x1,y1)为要转的点,(x2,y2)为中心点,如果是顺时针角度为-,
x=(x1-x2)cosθ-(y1-y2)sinθ+x2
y=(y1-y2)cosθ+(x1-x2)sinθ+y2
eg:bnu4226神技•八方鬼缚阵
就是简单的模拟加上点的旋转
代码:
/*I believe xiaoxuzizhucan*/ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<iostream> #include<math.h> #include<algorithm> using namespace std; #define MOD 10000000 typedef struct { int x; int y; } node; node q[1000005]; int main() { int cos=0; int sin=-1; //printf("%d\n",suan(0,0,1,0); // // int cos=0; // int sin=1; // int x=1; // int y=1; // int tx=0; // int ty=0; // int zx=tx*cos-ty*sin; // int zy=tx*sin+ty*cos; // printf("%d %d",zx,zy); int test; scanf("%d",&test); while(test--) { int n; scanf("%d",&n); n--; q[0].x=0; q[0].y=0; q[1].x=1; q[1].y=0; int count=2; int xia=1; while(n--) { int x2=q[xia].x; int y2=q[xia].y; int sbcount=count-1; for(int i=sbcount-1; i>=0; i--) { int x1=q[i].x; int y1=q[i].y; if(x1==x2&&y1==y2) continue; if(i==0) { //q[count].x= x2+y1-y2; q[count].x=(x1-x2)*cos-(y1-y2)*sin+x2; // q[count].y=x2+y2-x1; q[count].y= (y1-y2)*cos+(x1-x2)*sin+y2; xia=count; count++; } else { q[count].x=(x1-x2)*cos-(y1-y2)*sin+x2; // q[count].y=x2+y2-x1; q[count].y= (y1-y2)*cos+(x1-x2)*sin+y2; count++; } } } for(int i=0; i<count; i++) printf("%d %d\n",q[i].x,q[i].y); } }