Rotate
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 960 Accepted Submission(s): 448
Special Judge
Problem Description
Noting is more interesting than rotation!
Your little sister likes to rotate things. To put it easier to analyze, your sister makes n rotations. In the i-th time, she makes everything in the plane rotate counter-clockwisely around a point ai by a radian of pi.
Now she promises that the total effect of her rotations is a single rotation around a point A by radian P (this means the sum of pi is not a multiplier of 2π).
Of course, you should be able to figure out what is A and P :).
Your little sister likes to rotate things. To put it easier to analyze, your sister makes n rotations. In the i-th time, she makes everything in the plane rotate counter-clockwisely around a point ai by a radian of pi.
Now she promises that the total effect of her rotations is a single rotation around a point A by radian P (this means the sum of pi is not a multiplier of 2π).
Of course, you should be able to figure out what is A and P :).
Input
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains an integer n denoting the number of the rotations. Then n lines follows, each containing 3 real numbers x, y and p, which means rotating around point (x, y) counter-clockwisely by a radian of p.
We promise that the sum of all p's is differed at least 0.1 from the nearest multiplier of 2π.
T<=100. 1<=n<=10. 0<=x, y<=100. 0<=p<=2π.
For each test case, the first line contains an integer n denoting the number of the rotations. Then n lines follows, each containing 3 real numbers x, y and p, which means rotating around point (x, y) counter-clockwisely by a radian of p.
We promise that the sum of all p's is differed at least 0.1 from the nearest multiplier of 2π.
T<=100. 1<=n<=10. 0<=x, y<=100. 0<=p<=2π.
Output
For each test case, print 3 real numbers x, y, p, indicating that the overall rotation is around (x, y) counter-clockwisely by a radian of p. Note that you should print p where 0<=p<2π.
Your answer will be considered correct if and only if for x, y and p, the absolute error is no larger than 1e-5.
Your answer will be considered correct if and only if for x, y and p, the absolute error is no larger than 1e-5.
Sample Input
1 3 0 0 1 1 1 1 2 2 1
Sample Output
1.8088715944 0.1911284056 3.0000000000
题目链接:题目链接
题意:n个点 n个对应的角度,将坐标系上的点绕着给出的n个点逐个逆时针旋转对应的角度(总共进行了n次旋转),求坐标系上的点相当于绕着哪一点(ansx,ansy)旋转了多少角度 (p) 到达n次旋转的状态。
思路:
(x,y)绕着(temx,temy)逆时针旋转p1度,得到坐标(x1,y1);
公式为:
x1=(x-temx)*cos(p1)-(y-temy)*sin(p1)+temx;
y1=(x-temx)*sin(p1)+(y-temy)*cos(p1)+temy;
其中 p就是各个旋转角度累加的和。
code:
#include<iostream>
#include<math.h>
#include<cstdio>
using namespace std;
const double pi = 2*acos(-1.0);
int main()
{
int cas,n;
double x1,x0,y1,y0,ansx,ansy,temx,temy,p,p1,x,y,xxx;
scanf("%d",&cas);
while (cas--)
{
scanf("%d",&n);
x1=x0=x=-1;
y1=y0=y=-1;
p=0.0;
for(int i=1; i<=n; i++)
{
scanf("%lf%lf%lf",&temx,&temy,&p1);
x1=(x-temx)*cos(p1)-(y-temy)*sin(p1)+temx;
y1=(x-temx)*sin(p1)+(y-temy)*cos(p1)+temy;
x=x1,y=y1;
p+=p1;
if(p>=pi)
p-=pi;
}
ansx=((x1-x0*cos(p)+y0*sin(p))*(1-cos(p))-(y1-x0*sin(p)-y0*cos(p))*sin(p))/(2-2*cos(p));
ansy=(y1-x0*sin(p)-y0*cos(p)+ansx*sin(p))/(1-cos(p));
printf("%.8lf %.8lf %.8lf\n",ansx,ansy,p);
}
return 0;
}