polygon | R Documentation |
Return the polygon and external angles for a set of (x, y) points
polygon(x, y)
x |
a numeric vector of x coordinates, a n by 2 matrix, or anything that
can be coerced to a matrix via |
y |
a numeric vector of y coordinates, only needed if x is a numeric vector |
Providing a set of vertices, polygon
provides the angles between
edges.
It is expected that the vertices are provided in an anti-clockwise order. The anti-clockwise order is needed when constructing the conformal mappings.
A sccm_pg
object. This is a list
with the following
elements:
a n by 2 matrix of the vertices defining the convex hull.
a numeric vector of the exterior angles for each of the vertices.
convex_hull
p2d
d2p
p2p
polar2cartesian
link{convex_hull}
xvec <- c(-1, -0.3, 1.2, 0.45, -2)
yvec <- c(-1, 1.2, -0.2, 1.8, 0.3)
pg <- sccm::polygon(xvec, yvec)
pg
pg$beta
plot(pg)
# Build a star
# the following builds the set of vertices, but not in a anti-clockwise
# order. This is visible in the plot as the result is an irregular polygon.
star <-
rbind(sccm::polar2cartesian(r = 1.0, theta = seq(0, 1.6, by = 0.4) * pi),
sccm::polar2cartesian(r = 0.6, theta = seq(0.2, 1.8, by = 0.4) * pi))
plot(sccm::polygon(star))
# reorder the vertices
star <- star[rep(1:5, each = 2) + rep(c(0, 5), times = 5), ]
plot(sccm::polygon(star))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.