#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();
}
网友评论