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}
]
<h2>n=1</h2>
> {0.00244676, Null}
[![enter image description here][1]][1]
<h2>n=100</h2>
> {0.233274, Null}
[![enter image description here][2]][2]
<h2>n=1000</h2>
> {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?
[1]: https://i.sstatic.net/6F8UkEBM.jpg
[2]: https://i.sstatic.net/VCodWkIt.jpg