POJ - 1106

2019-08-18  本文已影响0人  Poisson_Lee
#include <stdio.h>
#include <math.h>

#define PI 3.14159

typedef struct { int X; int Y; } P;

float GetAngle(P t, P p, float r) {
    double angle;
    int x = p.X - t.X;
    int y = p.Y - t.Y;
    if (pow(x, 2) + pow(y, 2) > pow(r, 2)) {
        return 100.0;
    }
    angle = asin(y/ sqrt(pow(x, 2) + pow(y, 2)));
    if (x < 0) {
        angle = PI - asin(y / sqrt(pow(x, 2) + pow(y, 2)));
    }
    return angle;
}

void main() {
    P t = {25, 25};
    P p = {23, 23};
    float r = 3.5;
    printf("%f", GetAngle(t, p, r));
    getchar();
}

上一篇 下一篇

猜你喜欢

热点阅读