Learn R Programming

pracma (version 1.4.5)

polyarea: Area of a Polygon

Description

Compute the area of the polygon given by the vertices in the vectors x and y.

Usage

polyarea(x, y)

Arguments

x
x-coordinates of the vertices defining the polygon
y
y-coordinates of the vertices

Value

  • Araea of the polygon as a positive number.

Details

If x, y are matrices of the same size, the areas of all polygons defined by corresponding columns are computed. Areas to the left of the edges are positive, those to the right are counted negative.

The absolute value of the sum of those areas will be returned. parts that are circulated in the mathematically negative sense will be counted as negative in this sum. If some points of self-intersection of the polygon line are not in the vertex set, the calculation will be inexact.

The computation is based on the Gauss polygon area formula.

See Also

trapz

Examples

Run this code
# Zu Chongzhi's calculation of pi (China, about 480 A.D.),
  # approximating the circle from inside by a regular 12288-polygon(!):
  phi <- seq(0, 2*pi, len=3*2^12+1)
  x <- cos(phi)
  y <- sin(phi)
  pi_approx <- polyarea(x, y)
  print(pi_approx, digits=8)  #=> 3.1415925 or 355/113

Run the code above in your browser using DataLab