Skip to main content
1 of 4
Anton
  • 2.1k
  • 1
  • 7
  • 23

Generate A Point Inside An Arbitrary Concave Polygon

Imagine I have an arbitrary concave polygon. I need to find/generate a point inside of it, efficiently.

RandomPoint@Polygon@points is relatively fast only for simple such polygons.

n=1;(* toy polygon complexity *) points=Join[Transpose[{Range[2*n+1]*5,Drop[Flatten@ConstantArray[{0,45},n+1],-1]}],Transpose[{Reverse@Range[2*n+1]*5-5,Drop[Flatten@ConstantArray[{55,10},n+1],-1]}]]; insidepoint=RandomPoint@Polygon@points;//RepeatedTiming Show[ Graphics@Thread@Line@Transpose[{points,RotateLeft@points}], Graphics@{Red,PointSize[Medium],Point@insidepoint} ] 

n=1

> {0.00244676, Null}

enter image description here

n=100

{0.233274, Null} enter image description here

n=1000

{2.84268, Null}

So, for complex polygons,RandomPoint@Polygon is very, very slow.

Is there a method to find a point inside a convex polygon efficiently, no matter the complexity?

Anton
  • 2.1k
  • 1
  • 7
  • 23