Code covered by the BSD License  

Highlights from
Grid of points within a polygon

3.5

3.5 | 2 ratings Rate this file 46 Downloads (last 30 days) File Size: 1.5 KB File ID: #41454
image thumbnail

Grid of points within a polygon

by

 

22 Apr 2013 (Updated )

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

| Watch this File

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)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
07 May 2013 Shaun VanWeelden

Works just as described, great file!

23 Apr 2013 Anton Semechko

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

23 Apr 2013 Sulimon Sattari

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.

23 Apr 2013 Richard Crozier

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.

23 Apr 2013 Bruno Luong

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

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

23 Apr 2013 Anton Semechko

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.

23 Apr 2013 Sulimon Sattari

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.

22 Apr 2013 Anton Semechko

just wondering, how would this be useful to anyone?

Updates
23 Apr 2013

clarified description

23 Apr 2013

Better syntax and running time

23 Apr 2013

Updated text to go with my previous file update

08 May 2013

fixed a typo

Contact us