计算几何模板
作者:互联网
using namespace std;
typedef long double ld;
const ld eps = 1e-8;
const int N = 50009;
struct Point {
ld x, y;
Point(ld X = 0, ld Y = 0) { x = X, y = Y; }
Point operator-(Point a) { return Point(x - a.x, y - a.y); }
Point operator+(Point a) { return Point(x + a.x, y + a.y); }
ld operator*(Point a) { return x * a.y - y * a.x; }
Point operator*(ld a) {return Point(x * a,y * a);}
ld dis() {
return sqrt(x * x + y * y);
}
void out() {
printf("%.2Lf %.2Lf\n", x,y);
}
} p[N];
int dcmp(ld a, ld b) {
if (fabs(a-b)< eps)return 0;
else if (a > b)return 1;
else return -1;
}
typedef Point Vector;
struct Line {
Point p1, p2;
Vector v;
//Line(Point P1= {}, Point P2 = {}, Vector V = {}) {p1 = P1, p2=P2, v = V;}
void out() {
printf("%.2Lf %.2Lf -> %.2Lf %.2Lf\n", p1.x,p1.y, p2.x, p2.y);
}
}L[N];
void out(ld x) {
printf("%.2Lf\n", x);
}
Point GetCross(Line a, Line b) {
Vector v = b.p1 - a.p1;
return b.p1 + (b.v * ((v * a.v) / (a.v * b.v)));
}
标签:ld,%.,return,Point,2Lf,p1,计算,几何,模板 来源: https://www.cnblogs.com/Xiao-yan/p/14690764.html