Description Usage Arguments Value Author(s) Examples
View source: R/generate_random_polygon.R
This function generates a random polygon. It uses the polar coordinate representation, where the angles are evenly spaced over the interval [0, 2pi] and the radiuses are sampled from a uniform distribution.
1 2 3 4 5 6 7 | generate_random_polygon(
center = c(0, 0),
min.radius = 0.5,
max.radius = 1,
num.vertices = 5,
seed = NULL
)
|
center |
The "center" of the polygon, which determines its position. Should either be a 1 x 2 data frame/matrix or a numeric vector with 2 elements. |
min.radius, max.radius |
The minimum and maximum bounds used in the uniform distribution that samples the radius values |
num.vertices |
The number of vertices that the random polygon should contain |
seed |
The seed used when sampling the radius value |
A data frame that contains one row per vertex in the polygon, and the
columns x
and y
.
Mathias Isaksen mathiasleanderi@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # A random polygon with center (5, 10) and 10 vertices. The distance from
# the center to the vertices is between 4 and 10
vertex.df = generate_random_polygon(
center = c(5, 10),
min.radius = 4,
max.radius = 10,
num.vertices = 10,
seed = 123
)
library(ggplot2)
# The center of the polygon is shown in red
ggplot()+
geom_polygon(data = vertex.df, aes(x = x, y = y))+
geom_point(aes(x = 5, y = 10), color = "red")+
coord_fixed()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.