hdu 4998 Rotate 计算几何 点的旋转


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 :).
 

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

题目链接:题目链接

题意: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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值