compute_regular_polygons: Compute regular polygons

Description Usage Arguments Value Author(s) Examples

View source: R/compute-regular-polygons.R

Description

This function computes one or more regular polygons.

Usage

1
2
3
4
5
6
7
8
compute_regular_polygons(
  center = c(0, 0),
  radius = 1,
  rotation = 0,
  num.edges = 50,
  include.info = TRUE,
  ...
)

Arguments

center

Specifies the center(s) of the polygon(s). Can either be a numeric vector of length 2 (every polygon has the same center), or a data frame/matrix with 1 row per polygon. If the data frame/matrix has columns named x and y, these are used as center coordinates. Otherwise, the first two columns are used.

radius

The radius of the circumscribed circle of the polygon. Can either be a single number or a vector containing one radius per polygon.

rotation

The amount of rotation applied to the polygon(s), in radians. If rotation = 0, then the first vertex is at the "top" of the polygon. Can either be a single number or a vector containing a different rotation per polygon.

num.edges

The number of edges that the polygon(s) contain. Can either be a single integer or a vector containing a different number of edges per polygon.

include.info

If true, the returned data frame will contain the values for radius, rotation and num.edges as columns.

...

Custom properties that can be used to store additional information about the polygon(s), such as color and opacity. Can either be a single value or a vector containing a different value per polygon.

Value

A data frame where each row corresponds to the vertex of a polygon. The following columns are included:

x, y

The coordinates of the vertex

group

The group number of the polygon

radius, rotation, num.edges

The parameters that are specified in the function call. Only included if include.info = TRUE

...

Custom columns that are specified in the function call.

Author(s)

Mathias Isaksen mathiasleanderi@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
set.seed(123)
# This generates 10 polygons with different centers, an individual number of edges
# and a custom property "color"
vertex.df = compute_regular_polygons(
  center = data.frame(x = 1:10, y = 1:10),
  radius = 0.5,
  num.edges = 3:12,
  color = sample(c("red", "blue", "green"), 10, replace = TRUE)
)

library(ggplot2)
ggplot()+
  geom_polygon(data = vertex.df, aes(x = x, y = y, group = group, fill = color))+
  scale_fill_identity()+
  coord_fixed()

mathiasisaksen/artKIT documentation built on Dec. 21, 2021, 2:52 p.m.