//FuthorclySLM专用几何模板库 #include<iostream> #include<cmath> using namespace std; const double eps = 1e-7; struct Point { double x,y; Point(const double &xt,const double &yt):x(xt),y(yt){} double dist(const Point &next) { return sqrt((x-next.x)*(x-next.x)+(y-next.y)*(y-next.y)); } double dist_sour() const { return sqrt(x*x+y*y); } }; struct Seg { Point a,b; Seg(const Point &A,const Point &B):a(A),b(B){} }; int dblcmp(const double &d) { if(fabs(d) < eps) return 0; return d>0?1:-1; } double Cross(const Point &p,const Point &a,const Point &b) { return (a.x - p.x)*(b.y - a.y)-(a.y - p.y)*(b.x - p.x); } double Dot(const Point &v1, const Point &v2)//向量v1,v2的点乘 { return v1.x * v2.x + v1.y * v2.y; } bool Simple_cross(const Seg &A, const Seg &B)//求线段A,B是否规范相交 { return ( dblcmp(Cross(A.a,B.a,B.b))^dblcmp(Cross(A.b,B.a,B.b)) == -2 && dblcmp(Cross(B.a,A.a,A.b))^dblcmp(Cross(B.b,A.a,A.b)) == -2); } double alpha(const Point &v1, const Point &v2)//求向量v1,v2的夹角 { double xmt = v1.dist_sour()*v2.dist_sour(); return acos(Dot(v1,v2)/xmt); } inline int xyCmp(double p, double mini, double maxi) { return dblcmp(p-mini)*dblcmp(p-maxi); } inline int betweenCmp(const Point &a, const Point &b,const Point &c)//判断点c是否在ab范围内 { if(fabs(b.x-c.x)>fabs(b.y-c.y)) return xyCmp(a.x, min(b.x,c.x), max(b.x,c.x)); else return xyCmp(a.y, min(b.y,c.y), max(b.y,c.y)); } int Seg_cross(const Seg &A, const Seg &B, Point &p)//求线段相交的交点p,若非规范相交则返回2,不相交返回0 { double s1 = Cross(A.a,A.b,B.a), s2 = Cross(A.a,A.b,B.b), s3 = Cross(B.a,B.b,A.a), s4 = Cross(B.a,B.b,A.b); int d1 = dblcmp(s1), d2 = dblcmp(s2), d3 = dblcmp(s3), d4 = dblcmp(s4); if((d1^d2) == -2 && (d3^d4) == -2)//规范相交 { p.x = (B.a.x*s2-B.b.x*s1)/(s2-s1); p.y = (B.a.y*s2-B.b.y*s1)/(s2-s1); return 1; } //非规范相交,若四个端点中三点共线且某个点在另一条直线上 if(d1 == 0 && betweenCmp(B.a,A.a,A.b) <= 0 || d2 == 0 && betweenCmp(B.b,A.a,A.b) <= 0 || d3 == 0 && betweenCmp(A.a,B.a,B.b) <= 0 || d4 == 0 && betweenCmp(A.b,B.a,B.b) ) return 2; return 0; } int main() { return 0; }