runif_in_polygon: Uniform sampling in a polygon

Description Usage Arguments Details Value Examples

View source: R/polygon.R

Description

Uniform sampling in a polygon (dimension 2).

Usage

1
runif_in_polygon(n, vertices, center = "centroid")

Arguments

n

number of simulations

vertices

two-columns matrix giving the vertices (rows); the vertices must be ordered (clockwise or counterclockwise)

center

a point with respect to which the polygon is star-shaped, or "centroid" (default) to take the centroid (see Details)

Details

This function works for a star-shaped polygon, that is, a polygon that contains a point from which the entire polygon boundary is visible. This point must be given in the center argument. If the polygon is convex, any point inside the polygon is suitable (thus the default option of the center argument is appropriate in this case).

Value

The simulations in a n times 2 matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
vs <- matrix(c(0.951056516295154, 0.309016994374947,
               0.224513988289793, 0.309016994374947,
               -0.951056516295154, 0.309016994374948,
               -0.363271264002681, -0.118033988749895,
               0.587785252292473, -0.809016994374948,
               0.36327126400268, -0.118033988749895,
               0, 1,
               -0.224513988289793, 0.309016994374947,
               -0.587785252292473, -0.809016994374947,
               0, -0.381966011250105),
             ncol=2, byrow=TRUE)
sims <- runif_in_polygon(500, vs)
plot(sims, xlim=c(-1,1), ylim=c(-1,1), pch=19, asp=1)

stla/uniformly documentation built on Aug. 10, 2018, 7:03 a.m.