Create random point inside region, but with constraint on proximity to edge?

Supreme Blorgon shared this question 4 years ago
Answered

I have a highly irregular polygon, inside of which I'm trying to create a circle of a certain radius. The problem is that sometimes RandomPointIn[] puts a point on or near the edge of the region, and I need the random point to be at least the circle's radius away from the edge.


Here are some pictures of what I mean, with just an example polygon.


Point P would be the result of the RandomPointIn[] command:


OKAY:

4c22212898


ALSO OKAY:

cc23cadf2d


NOT OKAY:

29caec345b


I've tried drawing a new polygon inside the original, but because the polygons I'm working with are a lot more complicated (90+ vertices), it's difficult to ensure that any point on the edge of the smaller polygon will always be at least the circle's radius away from the old polygon.


Is there any way to restrict the region for an irregular polygon? OR ALTERNATIVELY, is there any way to just create a random circle inside the region, instead of placing a random point and constructing the circle around it? OR ALTERNATIVELY, can I create a circle of desired radius and then drag it along the inside of the polygon (like in image #2) with trace recording to spreadsheet, and make the new polygon from the traced points? How would I go about constraining the circle so that it can't cross the original polygon's edge?

Comments (7)

photo
1

one solution: repeat creating random point util the cirlce is in the polygon.


see:

photo
1

Sorry, won't work. I need this to be consistent behavior.

photo
photo
1

another solution: when the point is dragged, if the cicle is out of the polygon, let the point go back to ok position.

photo
1

something like your 2.way (alternatively) but realized with another principle (Version01)

Or reverse: first create the inside-polygon (for the center of circel) and then the outside polygon (Version02)

photo
1

Hi,

clic on P to replace

with :

P'=Translate[P, Vector[r UnitVector[Vector[ClosestPoint[poly1, P], P]]]]

script OnClic P :

UpdateConstruction[]

SetValue[P,RandomPointIn[poly1]]

SetValue[P,If[Distance[P,ClosestPoint[poly1,P]]<r,P',P]]

If[Distance[P,ClosestPoint[poly1,P]]<r,RunClickScript[P]]

...

photo
1

my contribution

photo
1

complete with RandomPointIn[poly2]

© 2021 International GeoGebra Institute