polygon: Polygon

View source: R/polygon.R

polygonR Documentation

Polygon

Description

Return the polygon and external angles for a set of (x, y) points

Usage

polygon(x, y)

Arguments

x

a numeric vector of x coordinates, a n by 2 matrix, or anything that can be coerced to a matrix via as.matrix.

y

a numeric vector of y coordinates, only needed if x is a numeric vector

Details

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.

Value

A sccm_pg object. This is a list with the following elements:

vertices

a n by 2 matrix of the vertices defining the convex hull.

beta

a numeric vector of the exterior angles for each of the vertices.

See Also

convex_hull p2d d2p p2p

polar2cartesian link{convex_hull}

Examples

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))


dewittpe/sccm documentation built on Feb. 2, 2024, 5:25 p.m.