Learn R Programming

monogeneaGM (version 1.1)

anglePolygon: Internal angles of a polygon

Description

This function computes the internal angles of a polygon, given the coordinates of its vertices.

Usage

anglePolygon(point, degree = FALSE)

Arguments

point
a list containing coordinates of the polygon vertices in either clockwise or anti-clockwise direction
degree
if TRUE, returns the internal angles in degrees instead of radians

Value

A list with two components:
angle
a matrix; the rows represents the vertices and the columns contain the latters' geometrical information: first column for x coordinate, second column for y coordinate, and third column for the assocaited internal angle (in radians)
orientation
a character indicating the direction of ordering the vertices: m for anti-clockwise and p for clockwise

Details

The sum of all the internal angles of a polygon with n-vertices must be equal to the product of n-2 with 180 (degrees) or pi (radians). This function is useful for detecting tps data files that contain errors (e.g. wrong sequence of digitizing landmarks, missing landmarks) so that corrective steps can be taken.

References

Khang TF, Soo OYM, Tan WB, Lim LHS. (2016). Monogenean anchor morphometry: systematic value, phylogenetic signal, and evolution. PeerJ 4:e1668.

Examples

Run this code
#internal angles of a right-angled triangle in degrees
anglePolygon(list(c(0,1),c(0,0),c(1,0)),degree=TRUE)

data(ligophorus_tpsdata)

#polygonal approximation of anchor shape
#the right ventral anchor
anchorpolygon <- anglePolygon(matrix2list(ligophorus_tpsdata$bantingensis[[1]][1:11,]), degree=TRUE)

#there are 11 landmarks, do the sum of internal angles should be (11-2)x180 = 1620
sum(anchorpolygon$angle[,3])

#does this make sense?
polyVis(1, havelist=TRUE, listdata=ligophorus_tpsdata$bantingensis)

Run the code above in your browser using DataLab