3

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}]}, {head, tail} = TakeDrop[points, RandomInteger[{2, Length[points] - 1}]]; Join[head, rotator[tail, t]] ]

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}]

enter image description here

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.

flinty
  • 25,147
  • 2
  • 20
  • 86

0 Answers0