R: Calculations for Polygons in the Plane

methods.xypolygon {spatstat.utils} | R Documentation

## Calculations for Polygons in the Plane

### Description

Compute the area or boundary length of a polygon, determine whether a point falls inside a polygon, compute the area of overlap between two polygons, and related tasks.

### Usage

    verify.xypolygon(p, fatal = TRUE)
    is.hole.xypolygon(polly)
    Area.xypolygon(polly)
    bdrylength.xypolygon(polly)
    reverse.xypolygon(p, adjust=FALSE)
    overlap.xypolygon(P, Q)
    simplify.xypolygon(p, dmin)
    inside.xypolygon(pts, polly, test01, method)

### Arguments

`p,polly,P,Q` | Data representing a polygon. See Details.
`dmin` | Single numeric value giving the minimum permissible length of an edge in the simplified polygon.
`fatal` | Logical value indicating whether failure is a fatal error.
`pts` | Coordinates of points to be tested. A named list with entries `x,y` which are numeric vectors of coordinates.
`adjust` | Logical value indicating whether internal data should be adjusted. See Details.
`test01,method` | For developer use only.

### Details

In the spatstat family of packages, a polygon in the Euclidean plane is represented as a named list with the following entries:

`x`,`y`

  Numeric vectors giving the coordinates of the vertices. The vertices should be traversed in anti-clockwise order (unless the polygon is a hole, when they should be traversed in clockwise order) and the last vertex should not repeat the first vertex.

hole

  Optional. A logical value indicating whether the polygon is a hole.

area

  Optional. Single numeric value giving the area of the polygon (negative if it is a hole).

The function `verify.xypolygon` checks whether its argument satisfies this format. If so, it returns `TRUE`; if not, it returns `FALSE` or (if `fatal=TRUE`) generates a fatal error.

The other functions listed here perform basic calculations for polygons using elementary Cartesian analytic geometry in R.

`is.hole.xypolygon` determines whether a polygon is a hole or not.

`Area.xypolygon` computes the area of the polygon using the discrete Green's formula.

`bdrylength.xypolygon` calculates the total length of edges of the polygon.

`reverse.xypolygon` reverses the order of the coordinate vectors `x` and `y`. If `adjust=TRUE`, the other entries `hole` and `area` will be adjusted as well.

`overlap.xypolygon` computes the area of overlap between two polygons using the discrete Green's formula. It is slow compared to the code in the polyclip package.

`simplify.xypolygon` removes vertices of the polygon until every edge is longer than `dmin`.

`inside.xypolygon(pts, polly)` determines whether each point in `pts` lies inside the polygon `polly` and returns a logical vector.

### Value

`verify.xypolygon` and `is.hole.xypolygon` return a single logical value.

`inside.xypolygon` returns a logical vector.

`Area.xypolygon`, `bdrylength.xypolygon` and `overlap.xypolygon` return a single numeric value.

`reverse.xypolygon` and `simplify.xypolygon` return another polygon object.

### Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au.

### Examples

      p <- list(x=c(0,1,4,2), y=c(0,0,2,3))
      is.hole.xypolygon(p)
      Area.xypolygon(p)
      bdrylength.xypolygon(p)
      overlap.xypolygon(p, list(x=p$x+1, y=p$y+1))
      reverse.xypolygon(p)

      plot(c(0,5),c(0,3),type="n",xlab="x", ylab="y")
      polygon(p)
      polygon(simplify.xypolygon(p, 1.1), lty=3)

      plot(c(0,5),c(0,3),type="n",xlab="x", ylab="y")
      polygon(p)
      xx <- runif(10, max=5)
      yy <- runif(10, max=3)
      points(xx, yy)
      ok <- as.logical(inside.xypolygon(list(x=xx, y=yy), p))
      points(xx[ok], yy[ok], pch=16)

[Package spatstat.utils version 1.17-0 Index]