Beispiel #1
0
/// Boolean intersection test.
int Line::Intersect(Line & withOtherLine)
{
	// http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/

	int or1 = Orientation(start, stop, withOtherLine.start);
	int or2 = Orientation(start, stop, withOtherLine.stop);
	int or3 = Orientation(withOtherLine.start, withOtherLine.stop, start);
	int or4 = Orientation(withOtherLine.start, withOtherLine.stop, stop);

	// Ok, we got an intersection confirmed, now the question is what type.
	if (or1 != or2 && or3 != or4)
		return IntersectionType::GENERAL;
	 
	// Special Cases for colinearity, may be either be end-points occuring on the other line or complete colinearity.
	bool colinear1 = false, colinear2 = false;
	if (or1 == COLINEAR && PointOnSegment(start, stop, withOtherLine.start) ||
		or2 == COLINEAR && PointOnSegment(start, stop, withOtherLine.stop)) 
	{	
		colinear1 = true;
	}
	if (or3 == COLINEAR && PointOnSegment(withOtherLine.start, withOtherLine.stop, start) ||
		or4 == COLINEAR && PointOnSegment(withOtherLine.start, withOtherLine.stop, stop))
	{
		colinear2 = true;
	}
	
	if (colinear1 && colinear2)
	{
		return IntersectionType::COLINEAR;
	}
	else if (colinear1 || colinear2)
		return IntersectionType::POINT_IN_SEGMENT;

	return IntersectionType::NO_INTERSECTION;
}
Beispiel #2
0
int OnCHEdge(int u)
{
    int i;
    for (i=0;i<chnum;i++) if (PointOnSegment(p[u],p[res[i]],p[res[(i+1)%chnum]])) break;
    return i;
}