编程介的小学生
2018-11-15 12:02
采纳率: 92.6%
浏览 1.5k
已采纳

C语言编写程序计算圆上的点的坐标,怎么求解?

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • threenewbee 2018-12-14 15:04
    已采纳
    已采纳该答案
    打赏 评论
  • Italink 2018-11-15 15:16

    圆内接正三角形时,3个点彼此之间距离最大,可以先求角度(利用atan2可以由斜率得到角度),每次旋转120,用极坐标的方式再求直角坐标。

     #include<stdio.h>
    #include<math.h>
    #define PI 3.1415926
    int main() {
        double x, y, r, a;
        int n;
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            scanf("%lf%lf", &x, &y);
            r = sqrt(x*x + y * y);  //求半径
            a = atan2(y, x);    //求角度
            for (int i = 0; i < 2; i++) {
                a -= PI * 2 / 3;        //旋转120度
                x = r * cos(a);     //根据极坐标求直角坐标
                y = r * sin(a);
                printf("%0.3lf %0.3lf", x, y);
                if (i == 0)
                    printf(" ");
            }
            printf("\n");
        }
        return 0;
    }
    
    打赏 评论

相关推荐 更多相似问题