[模板]计算几何

struct point{
    double x, y;
};
struct line{
    double A, B, C;//Ax + By + C = 0;
};
line PPL(point a, point b){// 两点确定直线的一般式
    if(a.x == b.x) return line{1, 0, a.x};
    if(a.y == b.y) return line{0, 1, a.y};
    return line{b.y-a.y, a.x-b.x, b.x*a.y - a.x*b.y};
}
double p_L_d(point a, line b){// 点到直线距离
    return 1.0*fabs(b.A*a.x+b.B*a.y+b.C) / sqrt(b.A*b.A+b.B*b.B);
}
point Rotate(point p, double rad){ //逆时针旋转
    return point{p.x*cos(rad)-p.y*sin(rad),p.x*sin(rad)+p.y*cos(rad)};
}
View Code
原文地址:https://www.cnblogs.com/Ketchum/p/13397989.html