// Schnitt der Liniensegmente a1-a2 und b1-b2 // 0 = kein Schnitt, 1 = Schnitt, -1 = Beruehrung int isect(const vec& a1, const vec& a2, const vec& b1, const vec& b2) { double da1 = sgn_area(b1, b2, a1), da2 = sgn_area(b1, b2, a2), db1 = sgn_area(a1, a2, b1), db2 = sgn_area(a1, a2, b2); if (pos_neg(da1, da2) && pos_neg(db1, db2)) return 1; if (on_seg(a1, a2, b1) || on_seg(a1, a2, b2) || on_seg(b1, b2, a1) || on_seg(b1, b2, a2)) return -1; return 0;}
// 線分p1-p2と線分q1-q2の距離 Real distSeg(P p1, P p2, P q1, P q2) { if (p1==p2 && q1==q2) return q1.dist(p1); if (p1==p2) return distSeg(q1, q2, p1); if (q1==q2) return distSeg(p1, p2, q1); if (!parallel(p1, p2, q1, q2)) { P r = intersection(p1, p2, q1, q2); if (on_seg(p1, p2, r) && on_seg(q1, q2, r)) return 0; } Real ret = min(distSeg(p1, p2, q1), distSeg(p1, p2, q2)); ret = min(ret, min(distSeg(q1, q2, p1), distSeg(q1, q2, p2))); return ret; }