HDU 4998 Rotate(计算几何 绕点旋转)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4998

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

Source

2014 ACM/ICPC Asia Regional Anshan Online

解析系转载:

平面上有一个二维坐标轴上,进行n次操作,把坐标轴绕着(x,y) (这个坐标总是初始坐标轴的坐标) 逆时针转p弧度。

最后的结果相当于进行一次操作,即绕着(X, Y) 逆时针旋转了P弧度。求 X,Y,P,题目保证总有解.

其实可以发现,最后的P是n次的pi的和,因为这和绕什么点旋转无关。(画一个图理解一下吧)

对任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:

x0= (x - rx0)*cos(a) - (y - ry0)*sin(a)  + rx0 ;

y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;

可以假设两个点a, b(两个足够了), 任意指定其坐标, 可以算出旋转后的对应点a‘, b‘,

前面已经求出了P, 现在只要求出旋转中心A即可, 利用 dis(A, a) == dis(A, a‘) 和 dis(A, b) == dis(A, b‘) 直接列方程可以求出A的坐标!

代码如下:

#include <cstdio>
#include <cmath>
#define pi acos(-1.0)
int main()
{
    int  t;
    int n;
    double x1, y1, x2, y2, r;
    double tx1, ty1, tx2, ty2;
    double rx0, ry0, a;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        x1 = y1 = 0;
        x2 = y2 = 1;
        r = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%lf%lf%lf", &rx0, &ry0, &a);
            r += a;
            if(r >= 2*pi)
                r -= 2*pi;
            tx1 = (x1 - rx0) * cos(a) - (y1 - ry0) * sin(a) + rx0;
            ty1 = (x1 - rx0) * sin(a) + (y1 - ry0) * cos(a) + ry0;
            tx2 = (x2 - rx0) * cos(a) - (y2 - ry0) * sin(a) + rx0;
            ty2 = (x2 - rx0) * sin(a) + (y2 - ry0) * cos(a) + ry0;
            x1 = tx1, y1 = ty1;
            x2 = tx2, y2 = ty2;
        }
        double t1 = (x1*x1+y1*y1)*(2*y2-2)-2*y1*(x2*x2+y2*y2)+4*y1;
        double t2 = 4*y1-4*y1*x2+4*x1*y2-4*x1;
        double x = t1/t2;
        double t3 = (x1*x1+y1*y1)-2*x*x1;
        double t4 = 2*y1;
        double y = t3/t4;
        printf("%lf %lf %lf\n",x,y,r);
    }
    return 0;
}

PS:最后给出求解的方程:

我们设a的坐标为(0, 0),b的坐标为(1, 1);

A的坐标为(x, y);

①:dis(A, a) == dis(A, a‘) :(x - x1)2 + (y - y1)2 = (x
- 0)2 + (y - 0)2;

②:dis(A, b) == dis(A, b‘) :(x
- x2)2 + (y - y2)2 = (x - 1)2 + (y - 1)2;

联立①②方程解出A(x,
y)的坐标即可!

时间: 2024-10-17 16:26:51

HDU 4998 Rotate(计算几何 绕点旋转)的相关文章

HDU 4998 Rotate 计算几何 2014 ACM/ICPC Asia Regional Anshan Online

题意: 有一个平面放在一个二维坐标轴上 给定n个操作 (x,y) p 表示把平面绕着(x,y) 逆时针转p弧度. 最后的结果相当于平面绕着(X, Y) 逆时针旋转了P弧度. 求:X,Y,P 思路: 任取一个三角形ABC,然后根据n个操作得到A'B'C', 然后求外心. 旋转的角度就是相加..==为啥我也不大清楚,不是本弱写的. #include <cstdio> #include <algorithm> #include <iostream> #include <

hdu 4998 Rotate 点的旋转 银牌题

Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1232    Accepted Submission(s): 545Special Judge Problem Description Noting is more interesting than rotation! Your little sister likes to

HDU 4998 Rotate(计算几何)2014年鞍山赛区网络赛

Rotate                                                                           Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Special Judge Problem Description Noting is more interesting than rotation! Your litt

HDU 4998 Rotate (几何变换——旋转)

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

HDU 4998 Rotate

Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 210    Accepted Submission(s): 110 Problem Description Noting is more interesting than rotation! Your little sister likes to rotate things

HDU 4998 Rotate --几何

题意:给n个点(x,y,p),从1~n,一次每次所有点绕着第 i 个点(原来的)逆时针转pi个弧度,问最后所有点的位置相当于绕哪个点旋转多少弧度,求出那点X和弧度P 解法:直接模拟旋转,每次计算新的坐标,最后选两个新的点分别和他们原来的点连一条线,两条线的中垂线的交点即为圆心,求出了圆心就可以求出转了多少弧度了. 注意判中垂线垂直x轴的情况以及n==1的情况. 最后角度要根据位置关系判下正负. 代码: #include <iostream> #include <cstdio> #i

hdu 4643(计算几何)

题意:容易理解 分析:切换的地点为两个基站所在直线的中垂线与两座城市所在直线的交点. 代码实现: #include <cstdio> #include <cmath> #include <algorithm> #define maxn 60 #define eps 1e-7 using namespace std; int dcmp(double x) //控制精度 { if(fabs(x)<eps) return 0; else return x<0?-1

sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess set out immedia

计算几何之向量旋转

实际做题中我们可能会遇到很多有关及计算几何的问题,其中有一类问题就是向量的旋转问题,下面我们来具体探讨一下有关旋转的问题. 首先我们先把问题简化一下,我们先研究一个点绕另一个点旋转一定角度的问题.已知A点坐标(x1,y1),B点坐标(x2,y2),我们需要求得A点绕着B点旋转θ度后的位置. A点绕B点旋转θ角度后得到的点,问题是我们要如何才能得到A' 点的坐标.(向逆时针方向旋转角度正,反之为负)研究一个点绕另一个点旋转的问题,我们可以先简化为一个点绕原点旋转的问题,这样比较方便我们的研究.之后