Grid of points within a polygon

This function generates an array of points that lie within a given polygon
Updated 8 May 2013

View License

inPoints = polygrid(xv,yv,ppa) generates points that are within a polygon using help from the inpolygon function.

xv and yv are columns representing the vertices of the polygon, as used in the Matlab function inpolygon

ppa refers to the points per unit area you would like inside the polygon. Here unit area refers to a 1.0 X 1.0 square in the axes.

L = linspace(0,2.*pi,6); xv = cos(L)';yv = sin(L)'; %from the inpolygon documentation
inPoints = polygrid(xv, yv, 10^5)
plot(inPoints(:, 1),inPoints(:,2), '.k');

Cite As

Sulimon Sattari (2024). Grid of points within a polygon (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

fixed a typo

Updated text to go with my previous file update

Better syntax and running time

clarified description