ACM学习历程—Rotate(HDU 2014 Anshan网赛)(几何)
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 :).
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π.
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.
Sample Input
1
3
0 0 1
1 1 1
2 2 1
Sample Output
1.8088715944 0.1911284056 3.0000000000
如
图,如果整个屏幕按照A点逆时针旋转a度,就会如图虚线的坐标。根据旋转,可以得到任意一个点旋转后的坐标。还有一点就是旋转最后的综合角度就是直接旋转
角度之和。然后最后得到的O'点,可以通过综合角度a,算出综合旋转中心A。这个旋转中心可以通过先将O‘沿OO’方向移位,使得,OA=OO‘,然后将
O’按照O逆时针旋转到A,求得,旋转角度是pi/2-a/2。
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cmath> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <queue> 10 #include <vector> 11 #include <string> 12 #define inf 0x3fffffff 13 #define esp 1e-10 14 using namespace std; 15 void Rotate(double &x0, double &y0, double x, double y, double a) 16 { 17 double xx, yy; 18 xx = x0*cos(a) - y0*sin(a) + x*(1 - cos(a)) + y*sin(a); 19 yy = x0*sin(a) + y0*cos(a) + y*(1 - cos(a)) - x*sin(a); 20 x0 = xx; 21 y0 = yy; 22 } 23 int main() 24 { 25 //freopen ("test.txt", "r", stdin); 26 int T; 27 scanf ("%d", &T); 28 for (int times = 0; times < T; ++times) 29 { 30 double x0 = 0, y0 = 0, x, y, a, p = 0, ans, pi = 3.14159265358979323846; 31 int n; 32 scanf ("%d", &n); 33 for (int i = 0; i < n; ++i) 34 { 35 scanf ("%lf%lf%lf", &x, &y, &a); 36 p += a; 37 Rotate(x0, y0, x, y, a); 38 } 39 while (p > 2*pi) 40 { 41 p -= 2*pi; 42 } 43 ans = p; 44 double k = 1/sin(p/2.0)/2.0; 45 x0 = x0 * k; 46 y0 = y0 * k; 47 p = pi/2.0 - p/2.0; 48 Rotate(x0, y0, 0, 0, p); 49 printf ("%f %f %f\n", x0, y0, ans); 50 } 51 return 0; 52 }
posted on 2014-10-09 21:42 AndyQsmart 阅读(223) 评论(0) 编辑 收藏 举报