示例#1
0
文件: 11343.cpp 项目: pedrodelyra/uva
	bool intersects(segment& s) {
		auto det1 = det(p, q, s.p);
		auto det2 = det(p, q, s.q);
		auto det3 = det(s.p, s.q, p);
		auto det4 = det(s.p, s.q, q);

		return (equals(det1, 0) && contains(s.p)) || (equals(det2, 0) && contains(s.q)) ||
		       (equals(det3, 0) && s.contains(p)) || (equals(det4, 0) && s.contains(q)) || (det1 * det2 < -EPS && det3 * det4 < -EPS);
	}
示例#2
0
bool isIntersected(segment &s1, segment &s2)
{
    double cp1 = cp(s1.p1, s1.p2, s2.p1), cp2 = cp(s1.p1, s1.p2, s2.p2);
    double cp3 = cp(s2.p1, s2.p2, s1.p1), cp4 = cp(s2.p1, s2.p2, s1.p2);

    if ((cp1 * cp2 < 0) && (cp3 * cp4) < 0) return true;
    if (fabs(cp1) <= EPSILON && s1.contains(s2.p1)) return true;
    if (fabs(cp2) <= EPSILON && s1.contains(s2.p2)) return true;
    if (fabs(cp3) <= EPSILON && s2.contains(s1.p1)) return true;
    if (fabs(cp4) <= EPSILON && s2.contains(s1.p2)) return true;

    return false;
}
示例#3
0
bool isIntersected(segment s1, segment s2)
{
    line p = getLine(s1.p1, s1.p2), q = getLine(s2.p1, s2.p2);

    if (fabs(p.a * q.b - q.a * p.b) < EPSILON)
    {
        if (fabs(cp(s1.p1, s1.p2, s2.p1)) < EPSILON)
            return s1.contains(s2.p1) || s1.contains(s2.p2);
        return false;
    }

	point pi = getIntersection(p, q);
	return s1.contains(pi) && s2.contains(pi);
}