Code covered by the BSD License

### Highlights from Grid of points within a polygon

4.0
4.0 | 3 ratings Rate this file 5 Downloads (last 30 days) File Size: 1.5 KB File ID: #41454 Version: 1.8

# Grid of points within a polygon

### Sulimon Sattari (view profile)

22 Apr 2013 (Updated )

This function generates an array of points that lie within a given polygon

File Information
Description

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.

Example:
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');

Required Products MATLAB
MATLAB release MATLAB 8.1 (R2013a)
09 Jan 2015 Zhou

### Zhou (view profile)

07 May 2013 Shaun VanWeelden

### Shaun VanWeelden (view profile)

Works just as described, great file!

23 Apr 2013 Anton Semechko

### Anton Semechko (view profile)

you should consider incorporating the sampling density parameter (i.e. number of nodes per unit area of the polygon) into your function to actually make it useful

Comment only
23 Apr 2013 Sulimon Sattari

### Sulimon Sattari (view profile)

Hi Richard, this program takes in only a list of polygon vertices, not a list of data points that may or may not lie within the polygon. It returns a uniform grid of points that lie within the area specified by the polygon.

Comment only
23 Apr 2013 Richard Crozier

### Richard Crozier (view profile)

There's also John D'errico's inhull

http://www.mathworks.co.uk/matlabcentral/fileexchange/10226-inhull

to do the same thing, and it works in any number of dimensions.

Comment only
23 Apr 2013 Bruno Luong

### Bruno Luong (view profile)

This submission shows that the author does not understand the potential of built-in inpolygon() function, that can accomplish the same thing with much shorter syntax and faster runtime.

23 Apr 2013 Sulimon Sattari

### Sulimon Sattari (view profile)

Thanks, you are right I should get those points as a single list. If you have any other suggestions let me know.

Comment only
23 Apr 2013 Anton Semechko

### Anton Semechko (view profile)

Thanks for clearing that up. Just so you know, your implementation could be substantially improved. For example, you don't have to loop through the individual points to determine if they are inside a polygon. The 'inpolygon' function that you are currently using, will accept a list of points and will return a logical array that could be used to index the points that fall inside the polygon.

Comment only
23 Apr 2013 Sulimon Sattari

### Sulimon Sattari (view profile)

I think people who study functions with domain as a polygon in R2 could find this useful. Its currently used to study chaotic maps like the Henon map, with polygons formed by intersections of the stable and unstable manifolds.

Comment only
22 Apr 2013 Anton Semechko

### Anton Semechko (view profile)

just wondering, how would this be useful to anyone?

Comment only
23 Apr 2013 1.5

clarified description

23 Apr 2013 1.6

Better syntax and running time

23 Apr 2013 1.7

Updated text to go with my previous file update

08 May 2013 1.8

fixed a typo