poly_angles: Interior polygon angles

View source: R/geom_poly_angles.R

poly_anglesR Documentation

Interior polygon angles

Description

Calculates interior angles at each vertex of a non-self-intersecting polygon, in input order. Useful, for instance, in determining the angles of a mesh cross-section.

Usage

poly_angles(coords)

Arguments

coords

An Nx2 matrix-like object containing ordered xy point coordinates of the polygon vertices, one per row. First and last coordinates must match.

Value

a vector of interior angles (in degrees) at each input vertex (in input order). Note that if the majority of angles are negative, the polygon was drawn counter-clockwise; if the majority are positive, the polygon was drawn clockwise.

Note

Will trigger an error with self-intersecting or degenerate polygons.

Author(s)

Cornel M. Pop

Examples

p <- data.frame(x=c(1,4,3,4,1,1), y=c(1,1,2,3,3,1))
plot(p, type="l", asp=1)
p.a <- poly_angles(p)
text(p$x, p$y, labels=p.a[1:(nrow(p) - 1)], pos=3) # Show angles
text(p$x, p$y, labels=rownames(p)[1:(nrow(p) - 1)], pos=1) # Show vertex ID

cornelmpop/Lithics3D documentation built on Feb. 10, 2024, 11:54 p.m.