Generate a Grid Inside a Given Polygonal Boundary

DESCRIPTION:

Generates a grid of points and then clips them to lie within a given boundary.

USAGE:

poly.grid(boundary, nx, ny, size) 

REQUIRED ARGUMENTS:

boundary
a list with components named "x" and "y" or a matrix with 2 columns representing the vertices of a convex polygon. Endpoint need not be repeated.
nx
integer representing the number of cells in the horizontal direction.
ny
integer representing the number of cells in the vertical direction.

OPTIONAL ARGUMENTS:

size
numeric vector containing the size of each cell. If it has length one then the cells will be squared with the same side sizes. If it has length two then the cells will have width size[1] and height size[2].

VALUE:

a two-column matrix containing the coordinates of the resulting grid.

DETAILS:

A rectangular nx by ny grid is overlaid on the polygon defined by boundary and then those points that fall outside are dropped. If size is given then the values nx and ny are redundant and if given will be ignored.

SEE ALSO:

EXAMPLES:

plot(as.spp(bramble)) 
bramble.chull <- bramble[chull(bramble),] 
polygon(bramble.chull, den=0) 
points(poly.grid(bramble.chull, size=c(.1,.1)), col=2)