Back to problems

Find intersection of two line segments

Algorithm · Applied Intuition · Medium

Given two line segments in the 2D plane, AB and CD, decide whether they intersect. Segment AB has endpoints A(x1, y1) and B(x2, y2); segment CD has endpoints C(x3, y3) and D(x4, y4). Both segments are closed, so an intersection at an endpoint is counted. If the segments are collinear and share any portion of their lengths, that also counts as an intersection. Parallel segments that do not lie on the same line do not intersect. Return true when the two segments have at least…

Checking your access…