SegmentsIntersect - Maple Help

ComputationalGeometry

 SegmentsIntersect
 determine if two line segments intersect

 Calling Sequence SegmentsIntersect( L1, L2 ) SegmentsIntersect( L1, L2, intersection ) SegmentsIntersect( M, locs ) SegmentsIntersect( M, locs, intersection )

Parameters

 L1, L2 - line segments given as pairs of points in 2-D space M - an array of point coordinates in 2-D space. Each point is a row in the array. M must be C_order and datatype=float[8] locs - positive integer indices of the three rows of M to treat as input the first location is the point and the other two the ends of the segment

Description

 • This command returns true if the two line segments intersect and false if they do not.  It does so using four calls to PointOrientation.
 • If the intersection option is given and the segments do not intersect false will be returned, otherwise the coordinate of the intersection will be returned.
 • If one segment is completely contained within the other, the list of endpoints of the smaller segment will be returned.

Examples

 > $\mathrm{with}\left(\mathrm{ComputationalGeometry}\right):$
 > $\mathrm{SegmentsIntersect}\left(\left[\left[0,0\right],\left[1,1\right]\right],\left[\left[0,1\right],\left[1,0\right]\right]\right)$
 ${\mathrm{true}}$ (1)
 > $L≔\left[\left[1,0\right],\left[1,5\right]\right]:$
 > $K≔\left[\left[\left[1,-2\right],\left[1,-1\right]\right],\left[\left[0,1\right],\left[0,3\right]\right],\left[\left[2,1\right],\left[2,3\right]\right],\left[\left[1,6.5\right],\left[1,8\right]\right],\left[\left[1,6\right],\left[1.5,8\right]\right],\left[\left[0.5,4\right],\left[1.5,7\right]\right],\left[\left[0.5,0.5\right],\left[1,-0.75\right]\right],\left[\left[1,5\right],\left[1.5,6\right]\right],\left[\left[1,4.5\right],\left[1.5,5\right]\right],\left[\left[0.5,3.75\right],\left[1.5,3.5\right]\right],\left[\left[1,2.5\right],\left[1,3.5\right]\right],\left[\left[0.5,1.5\right],\left[1,2\right]\right],\left[\left[1,0\right],\left[1.5,-2\right]\right],\left[\left[1,0.5\right],\left[1,-0.5\right]\right]\right]:$
 > $\mathrm{plots}:-\mathrm{display}\left(\mathrm{plottools}:-\mathrm{line}\left(L\left[\right],\mathrm{legend}="L",\mathrm{color}="Red"\right),\mathrm{seq}\left(\mathrm{plottools}:-\mathrm{line}\left(K\left[i\right]\left[\right],\mathrm{legend}="K"‖i,\mathrm{color}="Blue"\right),i=1..7\right),\mathrm{seq}\left(\mathrm{plottools}:-\mathrm{line}\left(K\left[i\right]\left[\right],\mathrm{legend}="K"‖i,\mathrm{color}="Green"\right),i=8..14\right),\mathrm{axes}=\mathrm{boxed}\right)$

None of the blue segments intersect L

 > $\left\{\mathrm{seq}\left(\mathrm{SegmentsIntersect}\left(L,K\left[i\right]\right),i=1..7\right)\right\}$
 $\left\{{\mathrm{false}}\right\}$ (2)

All of the green segments intersect L

 > $\left\{\mathrm{seq}\left(\mathrm{SegmentsIntersect}\left(L,K\left[i\right]\right),i=8..14\right)\right\}$
 $\left\{{\mathrm{true}}\right\}$ (3)
 > $M≔\mathrm{Array}\left(\left[L\left[\right],\mathrm{seq}\left(k\left[\right],k\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}K\right)\right],\mathrm{datatype}=\mathrm{float}\left[8\right],\mathrm{order}=\mathrm{C_order}\right)$
 ${M}{≔}\begin{array}{c}\left[\begin{array}{cc}{1.}& {0.}\\ {1.}& {5.}\\ {1.}& {-2.}\\ {1.}& {-1.}\\ {0.}& {1.}\\ {0.}& {3.}\\ {2.}& {1.}\\ {2.}& {3.}\\ {1.}& {6.50000000000000}\\ {1.}& {8.}\\ {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{30 × 2 Array}}\end{array}$ (4)
 > $\mathrm{SegmentsIntersect}\left(M,\left[1,2,3,4\right],\mathrm{intersection}\right)$
 ${\mathrm{false}}$ (5)
 > $\mathrm{SegmentsIntersect}\left(M,\left[1,2,25,26\right],\mathrm{intersection}\right)$
 $\left[\begin{array}{cc}{1.}& {2.}\end{array}\right]$ (6)

Line 11, completely contained in L

 > $\mathrm{SegmentsIntersect}\left(M,\left[1,2,23,24\right],\mathrm{intersection}\right)$
 $\left[\left[\begin{array}{cc}{1.}& {2.50000000000000}\end{array}\right]{,}\left[\begin{array}{cc}{1.}& {3.50000000000000}\end{array}\right]\right]$ (7)

Line 14, partially overlaps L

 > $\mathrm{SegmentsIntersect}\left(M,\left[1,2,29,30\right],\mathrm{intersection}\right)$
 $\left[\left[\begin{array}{cc}{1.}& {0.}\end{array}\right]{,}\left[\begin{array}{cc}{1.}& {0.500000000000000}\end{array}\right]\right]$ (8)

Compatibility

 • The ComputationalGeometry[SegmentsIntersect] command was introduced in Maple 2019.