Rotate
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 815 Accepted Submission(s): 389
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
Source
题目大意:给出n个点及旋转角度p(P是弧度制),问二维平面的点分别绕着这n个点旋转对应的角度后,相当于整个二维平面绕那个点旋转多少弧度,误差不超过10^(-5)。
解题思路:
对于P(x,y)点绕定点A(x0,y0)旋转角度p,得到新的点 P’(X,Y),则有下列公式:
X = ( x - x0 )*cos(p) - ( y - y0 )*sin(p) + x0
Y = ( x - x0 )*sin(p) + ( y - y0 )*cos(p) + y0
我们不妨找一个不在数据范围内的点P(-1,-20),对该点做n次旋转变换,得到P‘(X,Y),而一次的旋转角SP就是n个p的加和。
则对于P、P’和SP,我们可以按照上面的旋转公式列一个二元一次方程组,解方程组即可。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#include <ctime>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-6)
#define inf (1<<28)
#define sqr(x) (x) * (x)
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
struct point
{
double x;
double y;
double p;
};
point P[15];
//旋转公式
point XUAN_ZHUAN(point a,point b,double p)
{
point c;
c.x=(b.x-a.x)*cos(p)-(b.y-a.y)*sin(p)+a.x;
c.y=(b.x-a.x)*sin(p)+(b.y-a.y)*cos(p)+a.y;
return c;
}
int main()
{
int i,n,t;
point p0,p1;
double sp;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
//寻找的P(-1,-20)点
p0.x=p1.x=-1.0;p0.y=p1.y=-20.0;
sp=0.0;
//n次旋转
for(i=0;i<n;i++)
{
scanf("%lf%lf%lf",&P[i].x,&P[i].y,&P[i].p);
p1=XUAN_ZHUAN(P[i],p1,P[i].p);
sp+=P[i].p;
while(sp>=2*pi)
sp=sp-(2*pi);
}
//二元一次方程组的解
double y=(p1.x*sin(sp)+p1.y*(1-cos(sp))-(p0.x*cos(sp)-p0.y*sin(sp))*sin(sp)-(p0.x*sin(sp)+p0.y*cos(sp))*(1-cos(sp)))/(2-2*cos(sp));
double x=(p1.x*(1-cos(sp))-p1.y*sin(sp)-(p0.x*cos(sp)-p0.y*sin(sp))*(1-cos(sp))+(p0.x*sin(sp)+p0.y*cos(sp))*sin(sp))/(2-2*cos(sp));
printf("%.6lf %.6lf %.6lf\n",x,y,sp);
}
return 0;
}