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

解析系转载:

平面上有一个二维坐标轴上,进行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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值