Skip to contents

d_regular_ngon() is a wrapper around d_polygon() to create regular polygon shaped paths. Its vectorized in its x, y, r, n, a, and offset arguments.

Usage

d_regular_ngon(
  x,
  y,
  r,
  n,
  a = 90,
  ...,
  offset = 0,
  origin_at_bottom = getOption("dee.origin_at_bottom", FALSE),
  height = getOption("dee.height")
)

Arguments

x

If y is NULL will be coerced by affiner::as_coord2d(). Else a numeric vector.

y

Either NULL or a numeric vector.

r

The radius of the regular polygon (where the vertices lay on).

n

The number of vertices.

a

The angle of the first vertex (will be coerced by affiner::degrees()).

...

Passed to d_polygon().

offset

If a positive number the distance for outward polygon offsetting. If a negative number the distance for inward polygon offsetting.

origin_at_bottom, height

If origin_at_bottom is TRUE then y (and any y1 and y2) coordinates is transformed by height - y for absolute coordinates and -y for relative coordinates.

Value

A dee() object.

Examples

# A pentagon
d5 <- d_regular_ngon(x = 5, y = 5, r = 4, n = 5)
if (requireNamespace("omsvg", quietly = TRUE) &&
    requireNamespace("nanosvgr", quietly = TRUE)) {
  plot(d5, height = 10, width = 10,
       fill = "magenta", stroke = "black", stroke_width = 4)
}

# A hexagon
d6 <- d_regular_ngon(x = 5, y = 5, r = 4, n = 6, offset = c(0, -1))
if (requireNamespace("omsvg", quietly = TRUE) &&
    requireNamespace("nanosvgr", quietly = TRUE)) {
  plot(d6, height = 10, width = 10,
       attrs = list(fill_rule = "evenodd"),
       fill = "magenta", stroke = "black", stroke_width = 4)
}