RANDOMPOINTINPOLYGON Generate random point(s) in a polygon. POINT = randomPointInPolygon(POLY) POINTS = randomPointInPolygon(POLY, NPTS) Generate random point(s) within the specified polygon. If the number of points is not specified, only one point is generated. POINT = randomPointInPolygon(POLY, NPTS, QRS) Specifies a Quasi-random number generator QRS used to generate point. coordinates (requires the statistics toolbox). Example % generate an ellipse-like polygon, and fill it with points elli = [50 50 50 30 30]; poly = ellipseToPolygon(elli, 200); pts = randomPointInPolygon(poly, 500); figure; hold on; drawPolygon(poly, 'k'); drawPoint(pts, 'b.'); axis equal; axis([0 100 0 100]); % use halton sequence to distribute points within the polygon qrs = haltonset(2, 'Skip', 1e3, 'Leap', 1e2); pts = randomPointInPolygon(poly, 500, qrs); figure; hold on; drawPolygon(poly, 'k'); drawPoint(pts, 'b.'); axis equal; axis([0 100 0 100]); See also polygons2d, randomPointInBox, drawPolygon
Package: matgeom