getArea: Function to calculate the area of a polygon

Description Usage Arguments Value Author(s) References Examples

Description

Calculates the area of a polygon

Usage

1
getArea(x, y = NULL)

Arguments

x

a vector of coordinates OR a 2-column matrix of coordinates OR a data frame with columns 'x' and 'y' containing the coordinates. The last pair of coordinates need not be the same as the first pair.

y

if x is a vector, the corresponding vector of coordinates, otherwise NULL

Value

The area of the polygon. If the vertices are listed in anticlockwise order, the area will be negative.

Author(s)

Andy Royle, adapted (slightly) by Mike Meredith

References

Andy Royle's function from scrbook package

Examples

1
2
3
4
5
6
7
8
9
# An arbitrary polygon
x <- c(0, 1, 4, 5)
y <- c(0, 1, 3, 1)
plot(x, y)
polygon(x, y)
getArea(x, y)

# A data frame with an anticlockwise listing
getArea(data.frame(y=c(0, 1, 3, 1), x=c(0, 5, 4, 1)))

mikemeredith/MMmisc documentation built on Nov. 8, 2019, 11:34 p.m.