hdu4998 Rotate【计算几何】

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 :). 
InputThe 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π. OutputFor 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

划重点!

一个点绕定点旋转的坐标公式:


在平面坐标上,任意点P(x1,y1),绕一个坐标点Q(x2,y2)旋转θ角度后,新的坐标设为(x, y)的计算公式:
[cpp] view plain copy
  1. x= (x1 - x2)*cos(θ) - (y1 - y2)*sin(θ) + x2 ;  
  2. y= (x1 - x2)*sin(θ) + (y1 - y2)*cos(θ) + y2 ;  

这道题里最后的旋转角度就是前面所有的旋转角度加起来 因为不管绕哪一个点旋转 整个画面都转过了相同的角度 画面上的每一个点也都转过了相同的角度

先设一个点 对于每一次旋转都对这个点进行旋转 就可以得到最后的时候这个点的坐标

在根据这个点最后的坐标与最开始的坐标 可以反推出旋转中心

emmm感觉自己高中学的几何的公式都忘光了 计算能力也大大下降 解一个复杂一点的方程都解不出了啊天哪好难过


#include <iostream>
#include <algorithm>
#include <cstring>

#include <cstdio>

#include <cmath>

using namespace std;
#define PI 3.1415926
#define EPS 1.0e-5

int t, n;
struct point{
    double x, y;
}p[15];

point rot(point& p, point& ding, double theta)
{
    point c;
    c.x = (p.x - ding.x) * cos(theta) - (p.y - ding.y) * sin(theta) + ding.x;
    c.y = (p.x - ding.x) * sin(theta) + (p.y - ding.y) * cos(theta) + ding.y;
    return c;
}

int main()
{
    cin>>t;
    while(t--){
        scanf("%d",&n);
        double anangle = 0.0;
        point a, b;
        a.x = -1.0; a.y = -20.0;
        b.x = -1.0; b.y = -20.0;
        for(int i = 0; i < n; i++){
            double angle;
            scanf("%lf%lf%lf",&p[i].x, &p[i].y, &angle);
            a = rot(a, p[i], angle);
            anangle += angle;
            while(anangle >= 2 * PI){
                anangle -= 2 * PI;
            }

        }

        point ans;
        ans.y =(a.x*sin(anangle)+a.y*(1-cos(anangle))-(b.x*cos(anangle)-b.y*sin(anangle))*sin(anangle)-(b.x*sin(anangle)+b.y*cos(anangle))*(1-cos(anangle)))/(2-2*cos(anangle));
        ans.x=(a.x*(1-cos(anangle))-a.y*sin(anangle)-(b.x*cos(anangle)-b.y*sin(anangle))*(1-cos(anangle))+(b.x*sin(anangle)+b.y*cos(anangle))*sin(anangle))/(2-2*cos(anangle));
        printf("%.6f %.6f %.6f
", ans.x, ans.y, anangle);
    }
    return 0;

}


原文地址:https://www.cnblogs.com/wyboooo/p/9643412.html