HDU - 1700(计算几何)

问题描述:

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


题目题意:题目给我们一个点的坐标,这个点在一个以原点0为圆心的圆上,求这个圆上的另外俩个点的坐标使得这个三角形的周长最长.

题目分析:考的主要是这个知识点:(边数一定)圆的内接正多边形的周长最长,我试图证了一下,发现数学知识不够用了,等找个机会问问高数老师(再补回来).

还有就是这是这个矢量旋转公式:

二维矢量旋转公式:点p(x1,y1) 绕点0(x0,y0)旋转r角度d(顺时针)的坐标

X=(x1-x0)*cos(r)-(y1-y0)*sin(r)+x0;

Y=(x1-x0)*sin(r)+(y1-y0)*cos(r)+y0;


代码如下:

#include
#include
#include
using namespace std;

const double epx=5*1e-4;
const double PI=acos(-1.0);

int main()
{
    int t;
    scanf("%d",&t);
    while (t--) {
        double x,y;
        scanf("%lf%lf",&x,&y);
        double r=2*PI/3;
        double x1=x*cos(r)-y*sin(r);
        double y1=x*sin(r)+y*cos(r);
        double x2=x*cos(2*r)-y*sin(2*r);
        double y2=x*sin(2*r)+y*cos(2*r);
        if (y2-y1>epx) {//注意细节,绝对值小于epx就是相等的了
            printf("%.3lf %.3lf %.3lf %.3lf\n",x1,y1,x2,y2);
        }
        else if (fabs(y1-y2)









你可能感兴趣的:(计算几何)