MATLAB: Xpos(i) in Polygonal domain

domainpolygonsxpos

Hi, I need to define random point positions within a polygonal domain. So far, I am only able to realize the random positions of my points in the quadratic plot window with
for i=1:6000 xpos(i)=100*rand; ypos(i)=100*rand; end
So I want to arrange these points arbitrary within a polygon. I would really appreciate any help.

Best Answer

You could generate random points in a rectangle enclosing the polygon and then choose the points that lie inside using inpolygon. The documentation for this function even provides an example that is similar to what you want to do.