# Crumpling up a line: how to tell if a Line self intersects?

I'm crumpling up lines by rotating them at random positions. That is I take a line, a random rotation angle, and a random pivot point, then every point beyond that gets rotated about the pivot by the angle.

rotator[points_, θ_] :=
With[{r = RotationMatrix[θ], p1 = points[[1]]},
(r . (# - p1) + p1) & /@ points
]

crumple[points_, θ_] :=
Module[{head, tail, t = RandomReal[{-θ/2, θ/2}]},
TakeDrop[points, RandomInteger[{2, Length[points] - 1}]];
]

points = {#, 0} & /@ Subdivide[2, 100];
result = NestList[crumple[#, 0.8] &, points, 500];
Manipulate[
Graphics[{Thick, Line[result[[i]]]}, Axes -> True,
PlotRange -> {{-1, 1}, {-1, 1}}, AspectRatio -> 1], {i, 1,
Length[result], 1}]



The trouble is the line will eventually self intersect given enough crumpling. So I'd like to be able to test if a Line self intersects so I can avoid any random rotations that lead to invalid configurations.

• Does this answer your question? Implementation of Balaban's Line intersection algorithm in Mathematica Namely: FindIntersections[Line[result[[i]]]] Commented Mar 25 at 12:39
• data = Cases[ RegionMeshFindSegmentIntersections[Line@#, "ReturnSegmentIndex" -> True], {"SegmentsIntersect", indexs_} :> indexs, -1] & /@ result ? cf. mathematica.stackexchange.com/a/293936/72111 Commented Mar 25 at 12:55
• First[RegionMeshFindSegmentIntersections[line,"Ignore"->{"EndPointsTouching"}]]
– yode
Commented Mar 25 at 14:11