POJ - 1031

# include 
# include 

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();

}

你可能感兴趣的:(POJ - 1031)