npolygon: n-sided polygons Calculate the coordinates for an nsided...

Description Usage Arguments Value Examples

View source: R/polygons.R

Description

n-sided polygons Calculate the coordinates for an nsided polygon

Usage

1
npolygon(x = 0, y = 0, n = 6L, r = 1, d = 2 * pi/(n)/2)

Arguments

x, y

Numeric scalar. Origin of the polygon.

n

Integer scalar. Number of sides.

r

Numeric scalar. Radious of the polygon.

d

Numeric scalar. Starting degree in radians.

Value

A two column matrix with the coordinates to draw a n sided polygon.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
graphics.off()
oldpar <- par(no.readonly = TRUE)

par(xpd = NA, mfrow = c(3, 3), mai = rep(0, 4))
for (n in c(2, 3, 4, 5, 6, 8, 12, 20, 50)) {

  plot.new()
  plot.window(c(-1.25,1.25), c(-1.25,1.25))

  for (i in seq(1, .0005, length.out = 200)) {
    col <- adjustcolor("tomato", alpha.f = i)
    polygon(npolygon(x=(i-1)/4, y = (i-1)/4, r = i, d = i-1, n = n),
            col = NA, border=col)
  }

  mtext(sprintf("n = %i", n), side = 1, line = -3)
}

par(oldpar)

netplot documentation built on June 16, 2021, 9:09 a.m.