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 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个点及旋转角度p(P是弧度制),问二维平面的点分别绕着这n个点旋转对应的角度后,相当于整个二维平面绕那个点旋转多少弧度,误差不超过10^(-5)。

解题思路:

对于P(x,y)点绕定点A(x0,y0)旋转角度p,得到新的点 P’(X,Y),则有下列公式:

X = ( x - x0 )*cos(p) - ( y - y0 )*sin(p)  + x0

Y = ( x - x0 )*sin(p) + ( y - y0 )*cos(p) + y0

我们不妨找一个不在数据范围内的点P(-1,-20),对该点做n次旋转变换,得到P‘(X,Y),而一次的旋转角SP就是n个p的加和。

则对于P、P’和SP,我们可以按照上面的旋转公式列一个二元一次方程组,解方程组即可。

代码如下:

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#include <ctime>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-6)
#define inf (1<<28)
#define sqr(x) (x) * (x)
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
struct point
{
    double x;
    double y;
    double p;
};
point P[15];
//旋转公式
point XUAN_ZHUAN(point a,point b,double p)
{
    point c;
    c.x=(b.x-a.x)*cos(p)-(b.y-a.y)*sin(p)+a.x;
    c.y=(b.x-a.x)*sin(p)+(b.y-a.y)*cos(p)+a.y;
    return c;
}
int main()
{
    int i,n,t;
    point p0,p1;
    double sp;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        //寻找的P(-1,-20)点
        p0.x=p1.x=-1.0;p0.y=p1.y=-20.0;
        sp=0.0;
        //n次旋转
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf%lf",&P[i].x,&P[i].y,&P[i].p);
            p1=XUAN_ZHUAN(P[i],p1,P[i].p);
            sp+=P[i].p;
            while(sp>=2*pi)
                sp=sp-(2*pi);
        }
        //二元一次方程组的解
        double y=(p1.x*sin(sp)+p1.y*(1-cos(sp))-(p0.x*cos(sp)-p0.y*sin(sp))*sin(sp)-(p0.x*sin(sp)+p0.y*cos(sp))*(1-cos(sp)))/(2-2*cos(sp));
        double x=(p1.x*(1-cos(sp))-p1.y*sin(sp)-(p0.x*cos(sp)-p0.y*sin(sp))*(1-cos(sp))+(p0.x*sin(sp)+p0.y*cos(sp))*sin(sp))/(2-2*cos(sp));
        printf("%.6lf %.6lf %.6lf\n",x,y,sp);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2025-01-23 00:28:06

HDU 4998 Rotate (几何变换——旋转)的相关文章

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 every

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

为了寻找等效旋转操作,我们任选两个点P0和Q0,分别绕这n个点旋转一定的角度后最终得到Pn和Qn 然后已知:P0和Pn共圆,Q0和Qn共圆.所以要找的等效旋转点就是这两个线段的垂直平分线交点O. 等效的角度的计算,可以利用已知的等腰三角形(这里有两个)△P0PnR,做一条垂线(三线合一的性质),再利用反三角函数计算半角,再乘二 还有一种特殊情况就是,如果答案比平角要大,我们计算的角度就不对了. 此时可以让P0逆时针旋转90°得到一个P1,然后将P1和Pn的坐标分别代入直线P0R的方程,如果异号,

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 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 计算几何 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 <

[LeetCode] Rotate List 旋转链表

Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL. 这道旋转链表的题和之前那道Rotate Array 旋转数组 很类似,但是比那道要难一些,因为链表的值不能通过下表来访问,只能一个一个的

[LeetCode] 61. Rotate List 旋转链表

Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1: Input: 1->2->3->4->5->NULL, k = 2 Output: 4->5->1->2->3->NULL Explanation: rotate 1 steps to the right: 5->1->2->3-&g