MultiSegmentIntersect - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ComputationalGeometry

  

MultiSegmentIntersect

  

determine if a line segment intersects a string of segments

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

MultiSegmentIntersect( M, opts )

MultiSegmentIntersect( M, S, opts )

Parameters

M

-

listlist or rtable of point coordinates to be used as endpoints of line segments. M can also be a list of multiple collections of points.

S

-

(optional) a collection of indices specifying the line segments given as type list(listlist(posint). When M is multiple collections of points, each entry in S indicates indices as the corresponding entry in M. If M is a single collection of points, all entries of S indicate indices into that one collection. When M is a single collection of points, S may also be of type listlist(posint) for convenience. If not given, the it is automatically generated from M using one of several ways determined by the mode option.

opts

-

one or more options, see the Options section.

Options

• 

self : true or false, return the intersection of line segments which have endpoints in the same collection. Default is false if multiple collections of points are given, and true if only one.

• 

mode : one of "pairs", "linestring", "polygon", or a list these. The default is "pairs".

• 

lazy : if lazy or lazy=true is given then the command stops after finding one intersection.

• 

output : one of "truefalse", "index", "coordinate". The default is "coordinate".

Description

• 

If M is a single collection of points, this command returns a list of all the points at which intersections occur. It does so using a version of the Bentley–Ottmann sweep line algorithm and repeated calls to SegmentsIntersect.

• 

If M is more than one collection of points, only the intersections of line segments in different collections are returned.  This is useful for giving a list of polygons and finding all the places the polygons intersect each other without including their corners.

• 

If a second argument S is not given then the segments are implied by M and the mode option.

– 

mode="pairs" : for each collection in M, adjacent pairs of points are taken as line segments.

– 

mode="linestring" : for each collection in M, points are taken as lying in sequence along a piecewise-linear curve, or line string.

– 

mode="polygon" : for each collection in M, the points are taken as the boundary of a (possibly self-intersecting) polygon. This is identical to mode="linestring" except that a segment will be added to join the last point to first point in each collection.

– 

mode can be a list in order to use a different mode on each point collection.

• 

The self option, if given, calculates the self-intersections of the segment collections. It is false by default unless only one collection of segments is given. In that case, self=false indicates that only intersections that occur at segment end-points should not be ignored.

• 

The output option controls the form of the output.  If "truefalse" true is returned if there are any intersections at all and false otherwise. If "index", the return value gives the indices of the end points of the line segments that intersect.  If M is a list of multiple collections of points, then an index into M is also returned: mi,b,e. This is useful if you wish to know exactly which segments intersect rather than just their intersection. In the case that an intersection can be determined to occur exactly at a vertex (this can only happen when self=true) the index is returned as exact,mi,i or exact,i in the case of one collection of points.

Examples

withComputationalGeometry:

plots:-setoptionsscaling=constrained,axes=none:

M0,0,0,1,1,1,1,0:

L0.5,1,0.5,2,0.5,1,0.5,2,1.5,1,1.5,2,0.75,1.5,1.25,0.5,0.25,0,1.25,0,0.2,1,0.4,1,0.25,0.5,0.25,0.25,0,0.5,0,1.5:

plots:-displayseqplottools:-lineLi,legend=L i,color=Red,i=1..nopsL,plottools:-polygonM,style=line,legend=M,axes=boxed

MultiSegmentIntersectL1,M,mode=polygon,output=truefalse

false

(1)

MultiSegmentIntersectL2,M,mode=polygon,output=truefalse

true

(2)

MultiSegmentIntersectL2,M,mode=polygon,lazy

0.500000000000000,−0.,0.500000000000000,1.

(3)

P, Q, and R are the vertices of three irregular polygons

P0.8485281372,0.3514718626,0.3514718626,0.8485281372,0.3514718628,0.8485281370,0.8485281373,0.3514718624,0.8485281368,0.3514718630,0.3514718614,0.8485281376,0.3514718633,0.8485281368,0.8485281374,0.3514718621:

Q0.07795711098,0.4379868877,0.9081886538,0.4686672090,0.3310509455,0.1314238396,0.07568485961,0.9992639501,0.3367585765,0.1931579319,0.8165279848,0.4289815143:

R0.5872000891,0.6460853196,0.06333536874,1.751487097,0.6288418341,0.6328017610,1.719345382,0.02678891621,0.5837772511,0.6164276625,0.05065049498,1.745456068,0.5734652878,0.4860444847,1.670119538,0.1041376233:

theplotplots:-displayplottools:-polygonP,style=line,color=Niagara 6,plottools:-polygonQ,style=line,color=Niagara 5,plottools:-polygonR,style=line,color=Niagara 9

segintsMultiSegmentIntersectP,Q,R,mode=polygon

segints0.848528137396171,−0.338014991924543,0.120039590504333,0.848528137134153,−0.00143898670186136,0.848528137099591,−0.770555651471915,−0.429444348202590,−0.796713219266504,−0.403286780450101,0.737635404097402,−0.462364595536458,0.821484869996484,−0.378515129536161,0.435447425512102,−0.764552574486531,0.625187746682136,−0.458209212271670,0.805041648484513,−0.361417944761064

(4)

plots:-displaytheplot,plottools:-pointsegints,symbol=circle,symbolsize=15,color=Black

Zooming confirms there is no intersection at x = -.5837772511

plots:-displaytheplot,plottools:-pointsegints,symbol=circle,symbolsize=15,color=Black,view=0.585..0.580,0.615..0.620,axes=box

a different mode option can consider the collections as points of non-closed curves

theplotplots:-displayplottools:-curveP,style=line,color=Niagara 6,plottools:-curveQ,style=line,color=Niagara 5,plottools:-curveR,style=line,color=Niagara 9

segintsMultiSegmentIntersectP,Q,R,mode=linestring

segints0.120039590504333,0.848528137134153,−0.00143898670186136,0.848528137099591,−0.796713219266504,−0.403286780450101,0.737635404097402,−0.462364595536458,0.821484869996484,−0.378515129536161,0.435447425512102,−0.764552574486531,0.625187746682136,−0.458209212271670,0.805041648484513,−0.361417944761064

(5)

plots:-displaytheplot,plottools:-pointsegints,symbol=circle,symbolsize=15,color=Black

Enabling userinfo for CompGeomPlot will show graphical steps of the algorithm

infolevelCompGeomPlot1:

MultiSegmentIntersectP,Q,R

MultiSegmentIntersect:

MultiSegmentIntersect:

−0.796713219266504,−0.403286780450101,0.737635404097402,−0.462364595536458,0.625187746682136,−0.458209212271670

(6)

MultiSegmentIntersectP,Q,R

MultiSegmentIntersect:

MultiSegmentIntersect:

−0.796713219266504,−0.403286780450101,0.737635404097402,−0.462364595536458,0.625187746682136,−0.458209212271670

(7)

MultiSegmentIntersectP,Q,R,mode=linestring

MultiSegmentIntersect:

MultiSegmentIntersect:

0.568350743082245,0.631649256717755,0.120039590504333,0.848528137134153,−0.00143898670186136,0.848528137099591,−0.796713219266504,−0.403286780450101,−0.790756202823990,−0.409243796883027,0.737635404097402,−0.462364595536458,0.821484869996484,−0.378515129536161,0.435447425512102,−0.764552574486531,0.800646260525579,−0.356847747854247,0.816931241317897,−0.355019369311793,0.625187746682136,−0.458209212271670,0.805041648484513,−0.361417944761064,0.254570590141784,0.391335878482655,0.351471862600000,0.848528137200000,−0.351471862800000,0.848528137000000,−0.848528137300000,0.351471862400000,−0.848528136800000,−0.351471863000000,−0.351471861400000,−0.848528137600000,0.351471863300000,−0.848528136800000,0.848528137400000,−0.351471862100000,0.0779571109800000,−0.437986887700000,0.908188653800000,−0.468667209000000,0.331050945500000,0.131423839600000,0.0756848596100000,0.999263950100000,−0.336758576500000,0.193157931900000,−0.816527984800000,−0.428981514300000,0.587200089100000,0.646085319600000,−0.0633353687400000,1.75148709700000,−0.628841834100000,0.632801761000000,−1.71934538200000,0.0267889162100000,−0.583777251100000,−0.616427662500000,−0.0506504949800000,−1.74545606800000,0.573465287800000,−0.486044484700000

(8)

The self option will also calculate polynomial vertices and any self-intersections

MultiSegmentIntersectP,Q,R,mode=polygon,self

MultiSegmentIntersect:

MultiSegmentIntersect:

0.848528137396171,−0.338014991924543,0.120039590504333,0.848528137134153,−0.00143898670186136,0.848528137099591,−0.770555651471915,−0.429444348202590,−0.796713219266504,−0.403286780450101,0.737635404097402,−0.462364595536458,0.821484869996484,−0.378515129536161,0.435447425512102,−0.764552574486531,0.625187746682136,−0.458209212271670,0.805041648484513,−0.361417944761064,0.848528137200000,0.351471862600000,0.351471862600000,0.848528137200000,−0.351471862800000,0.848528137000000,−0.848528137300000,0.351471862400000,−0.848528136800000,−0.351471863000000,−0.351471861400000,−0.848528137600000,0.351471863300000,−0.848528136800000,0.848528137400000,−0.351471862100000,0.0779571109800000,−0.437986887700000,0.908188653800000,−0.468667209000000,0.331050945500000,0.131423839600000,0.0756848596100000,0.999263950100000,−0.336758576500000,0.193157931900000,−0.816527984800000,−0.428981514300000,0.587200089100000,0.646085319600000,−0.0633353687400000,1.75148709700000,−0.628841834100000,0.632801761000000,−1.71934538200000,0.0267889162100000,−0.583777251100000,−0.616427662500000,−0.0506504949800000,−1.74545606800000,0.573465287800000,−0.486044484700000,1.67011953800000,0.104137623300000

(9)

The default modes and the mode option are meant to allow for convenience. The command can also take a single rtable of point coordinates together with a list of lists of index pairs specifying line segment end points in the point rtable. For best efficiency, the point rtable should be purely numerical and stored in C_order.

MMatrixP,Q,R,:-datatype=float8,:-order=:-C_order

Sseqi,i+1,i=1..81,8,1,seq8+i,8+i+1,i=1..61,8+6,8+1,seq14+i,14+i+1,i=1..81,14+8,14+1

S1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,1,9,10,10,11,11,12,12,13,13,14,14,9,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,15

(10)

MultiSegmentIntersectM,S

MultiSegmentIntersect:

MultiSegmentIntersect:

0.848528137396171,−0.338014991924543,0.120039590504333,0.848528137134153,−0.00143898670186136,0.848528137099591,−0.770555651471915,−0.429444348202590,−0.796713219266504,−0.403286780450101,0.737635404097402,−0.462364595536458,0.821484869996484,−0.378515129536161,0.435447425512102,−0.764552574486531,0.625187746682136,−0.458209212271670,0.805041648484513,−0.361417944761064

(11)

MultiSegmentIntersectM,S1,output=index

MultiSegmentIntersect:

MultiSegmentIntersect:

exact,1,exact,2,exact,3,exact,4,exact,5,exact,6,exact,7,exact,8

(12)

MultiSegmentIntersectM,S1,output=index,self=false

MultiSegmentIntersect:

MultiSegmentIntersect:

(13)

Compatibility

• 

The ComputationalGeometry[MultiSegmentIntersect] command was introduced in Maple 2019.

• 

For more information on Maple 2019 changes, see Updates in Maple 2019.

See Also

PointOrientation

SegmentsIntersect