Learn R Programming

Ternary (version 2.3.3)

Polygon-Geometry: Polygon geometry

Description

Geometry functions for irregular polygons.

Usage

PolygonArea(x, y = NULL, positive = TRUE)

PolygonCentre(x, y = NULL)

PolygonCenter(x, y = NULL)

GrowPolygon(x, y = NULL, buffer = 0)

Value

PolygonArea() returns the area of the specified polygon.

PolygonCentre() returns a single-row matrix containing the x and y coordinates of the geometric centre of the polygon.

GrowPolygon() returns coordinates of the vertices of polygon

after moving each vertex buffer away from the polygon's centre.

Arguments

x, y

Vectors containing the coordinates of the vertices of the polygon.

positive

If vertices are specified in an anticlockwise direction, the polygon will be treated as a hole, with a negative area, unless positive is set to TRUE. Vertices specified in a clockwise sequence always yield a positive area.

buffer

Numeric specifying distance by which to grow polygon.

Functions

  • PolygonArea(): Calculate the area of an irregular polygon

  • PolygonCentre(): Locate the centre of a polygon

  • GrowPolygon(): Enlarge a polygon in all directions

See Also

Other tiling functions: TriangleCentres(), TriangleInHull()

Examples

Run this code
x <- c(-3, -1, 6, 3, -4)
y <- c(-2, 4, 1, 10, 9)
plot(x, y, frame.plot = FALSE)
polygon(x, y)
PolygonArea(x, y)
points(PolygonCentre(x, y), pch = 3, cex = 2)
polygon(GrowPolygon(x, y, 1), border = "darkgreen",
        xpd = NA # Allow drawing beyond plot border
       )

# Negative values shrink the polygon
polygon(GrowPolygon(x, y, -1), border = "red")

Run the code above in your browser using DataLab