美文网首页
POJ - 1031

POJ - 1031

作者: Poisson_Lee | 来源:发表于2019-08-18 09:25 被阅读0次
# 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();

}

相关文章

网友评论

      本文标题:POJ - 1031

      本文链接:https://www.haomeiwen.com/subject/fptrsctx.html