area_polygon: Polygon area

Description Usage Arguments Value Examples

View source: R/polyArea.R

Description

Calculate the area of a non-intersecting polygon given its vertices

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
area_polygon(x, ...)

## Default S3 method:
area_polygon(x, y = NULL, ...)

## S3 method for class 'formula'
area_polygon(x, data = parent.frame(), ...)

## S3 method for class 'area_polygon'
print(x, ...)

Arguments

x, y

numeric vectors defining vertices in order. Any method recognized by grDevices::xy.coords() is accepted. Or a formula for other methods. Or an object of class "area_polygon"

...

Additional arguments, currently not used

data

a data frame

Value

An object of class "area_polygon". A single numerical value with the polygon area with an attribute giving the sign, as determined by the orientation of the vertices.

Examples

1
2
3
4
5
6
z <- complex(real = rnorm(200), imaginary = rnorm(200))
hz <- z[chull(z)]
plot(hz)
polygon(hz)
points(z, pch = ".", cex = 2, col = "red")
text(mean(hz), labels=paste("area =", area_polygon(hz)))

BillVenables/WWRGraphics documentation built on Feb. 1, 2021, 12:13 p.m.