POJ - 1031
2019-08-18 本文已影响0人
Poisson_Lee
# include <stdio.h>
# include <math.h>
typedef struct { double X; double Y; } Point;
double GetAngle(Point p1, Point p2) {
double angle;
double numerator = pow(p1.X, 2) + pow(p1.Y, 2) + pow(p2.X, 2) + pow(p2.Y, 2) \
- pow(p1.X - p2.X, 2) - pow(p1.Y - p2.Y, 2);
double denominator = 2 * sqrt(pow(p1.X, 2) + pow(p1.Y, 2)) \
* sqrt(pow(p2.X, 2) + pow(p2.Y, 2));
angle = acos(numerator/denominator);
return angle;
}
int main() {
Point p1, p2;
p1.X = 1; p1.Y = 0;
p2.X = 2; p2.Y = 0;
printf("%f", GetAngle(p1, p2));
getchar();
}