| sfshape_ngon | R Documentation |
Construct one or more regular polygons (equal sides and angles) as
sfg/sfc POLYGON geometry. sfshape_ngon()
builds a single polygon at a given center; sfshape_ngons() builds
n polygons, automatically arranged in a compact, non-overlapping
grid. Useful for building varied, non-hand-typed node geometries; see
the geometry vignette for examples, and sfshape_stars for
the star-shaped equivalent.
sfshape_ngon(cx = 0, cy = 0, sides = 5, radius = 1)
sfshape_ngons(n, sides = c(3, 5, 7), radius = 0.3, spacing = NULL)
cx, cy |
Numeric. Coordinates of the polygon's center.
( |
sides |
Integer. Number of sides; must be 3 or more. For
|
radius |
Numeric. Circumradius – distance from the center to each
vertex. For |
n |
Integer. Number of polygons to build. ( |
spacing |
Numeric. Distance between polygon centers in the
auto-generated grid. Defaults to |
sfshape_ngon() returns a single sfg object of type
POLYGON. sfshape_ngons() returns an sfc of
n such polygons.
sfshape_stars
if (requireNamespace("sf", quietly = TRUE)){
pentagon <- sfshape_ngon(0, 0, sides = 5, radius = 1)
hexagon <- sfshape_ngon(2, 0, sides = 6, radius = 1)
plot(sf::st_sfc(pentagon, hexagon))
many <- sfshape_ngons(7, sides = c(3, 5, 8), radius = 0.4)
plot(many)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.