This article focuses on the intersection of line segments.
Given two line segments, how can I tell if the two segments intersect?
If the two segments intersect, how do you find the intersection?
Line intersection problem is usually because of its complicated situation of the kind of people to avoid and far, here hope through the author's simplified discussion hope to help readers to comb the idea.
First, we try to draw a few geometric images to find out the intersection of a number of different cases, it is important to note that there may be readers will be curious, these intuitive to see the intersection of no difference, why do we think they are different? The answer is, here we need to use algebraic representations of geometric features to make judgments, so different geometric features, although all represent segments intersect, but the corresponding algebraic expressions are not necessarily the same.
The simple function code is as follows:
//General conditions of intersection of segmentsBOOLsegmentintersects (Point A1, Point A2, point B1, point B2) {DoubleC1 = Cross (A2-A1, b1-A1); DoubleC2 = Cross (A2-A1, b2-A1); DoubleC3 = Cross (B2-B1, a1-B1); DoubleC4 = Cross (B2-B1, a2-B1); if(DCMP (C1) *dcmp (c2) = =0&& dcmp (C3) *dcmp (C4) = =0) { if(Onsegment (Point A1, Point B1, point B2) | |Onsegment (Point A2, point B1, point B2))return true; Else return false; } return if(DCMP (C1) *dcmp (C2) <=0&& dcmp (C3) *dcmp (C4) <=0)}
"Algorithm problem combat strategy"-chaper15-compute Geometry-segment intersection