hdu 1700 Points on Cycle(坐标旋转)

http://acm.hdu.edu.cn/showproblem.php?pid=1700

Points on Cycle

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1567    Accepted Submission(s): 570


Problem Description
There is a cycle with its center on the origin.
Now give you a point on the cycle, you are to find out the other two points on it, to maximize the sum of the distance between each other
you may assume that the radius of the cycle will not exceed 1000.
 
Input
There are T test cases, in each case there are 2 decimal number representing the coordinate of the given point.
 
Output
For each testcase you are supposed to output the coordinates of both of the unknow points by 3 decimal places of precision 
Alway output the lower one first(with a smaller Y-coordinate value), if they have the same Y value output the one with a smaller X. 

NOTE
when output, if the absolute difference between the coordinate values X1 and X2 is smaller than 0.0005, we assume they are equal.
 
Sample Input
2
1.500 2.000
563.585 1.251
 
Sample Output
0.982 -2.299 -2.482 0.299
-280.709 -488.704 -282.876 487.453
 
 
-----------------------------------------------------------------------
坐标旋转公式:x1=x*cosα - y*sinα
                   y1=y*cosα + x*sinα
 其中,x,y表示物体相对旋转点旋转角度α之前的坐标;x1,y1表示物体旋转α角后相对于旋转点的坐标
具体证明去找书吧
 
还有,圆周率pi要开到3.14159265才可以
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include <algorithm>
 6 #define eps 0.0005
 7 #define pi 3.14159265
 8 int main()
 9 {
10     int n,m,i,j;
11     scanf("%d",&n);
12     while(n--)
13     {
14         double x1,y1,x2,y2,x3,y3;
15         double Q1=pi*2/3,Q2=pi*4/3;
16         scanf("%lf%lf",&x1,&y1);
17         x2=x1*cos(Q1)-y1*sin(Q1);
18         y2=y1*cos(Q1)+x1*sin(Q1);
19         x3=x1*cos(Q2)-y1*sin(Q2);
20         y3=y1*cos(Q2)+x1*sin(Q2);//printf("%.3lf %.3lf %.3lf %.3lf
",x2,y2,x3,y3);
21         if(fabs(y2-y3)<eps)
22         {
23             if((x2-x3)>eps)
24                 printf("%.3lf %.3lf %.3lf %.3lf
",x3,y3,x2,y2);
25             else
26             {
27                 printf("%.3lf %.3lf %.3lf %.3lf
",x2,y2,x3,y3);
28             }
29         }
30         else if((y2-y3)>eps)
31             printf("%.3lf %.3lf %.3lf %.3lf
",x3,y3,x2,y2);
32         else
33             printf("%.3lf %.3lf %.3lf %.3lf
",x2,y2,x3,y3);
34     }
35     return 0;
36 }
 

任意点(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 ;

原文地址:https://www.cnblogs.com/ccccnzb/p/3904864.html