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

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:

ALSO OKAY:

NOT OKAY:

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?

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

see:

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

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)

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

...

my contribution

complete with RandomPointIn[poly2]

Loading...Comments have been locked on this page!