Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

discpoly

Polygonal Approximation of a Disc/Circle


Description

Generates a polygon representing a disc/circle (in planar coordinates) as an object of one of three possible classes: "Polygon", "owin", or – if rgeos (or gpclib) are available – "gpc.poly".

Usage

discpoly(center, radius, npoly = 64,
         class = c("Polygon", "owin", "gpc.poly"),
         hole = FALSE)

Arguments

center

numeric vector of length 2 (center coordinates of the circle).

radius

single numeric value (radius of the circle).

npoly

single integer. Number of edges of the polygonal approximation.

class

class of the resulting polygon (partial name matching applies). For "owin", this is just a wrapper around spatstat.geom's own disc function.

hole

logical. Does the resulting polygon represent a hole?

Value

A polygon of class class representing a circle/disc with npoly edges accuracy.
If class="gpc.poly" although this formal class is not currently defined (and rgeos is not available), only the pts slot of a "gpc.poly" is returned with a warning.

Author(s)

Sebastian Meyer
This function is inspired by the disc function from package spatstat.geom.

See Also

disc in package spatstat.geom.

Examples

## Construct circles with increasing accuracy and of different spatial classes
disc1 <- discpoly(c(0,0), 5, npoly=4, class = "owin")
disc2 <- discpoly(c(0,0), 5, npoly=16, class = "Polygon")

## Look at the results
print(disc1)
plot(disc1, axes=TRUE, main="", border=2)

print(disc2)
lines(disc2, col=3)

if (requireNamespace("rgeos")) { # for the "gpc.poly" class definition
    disc3 <- discpoly(c(0,0), 5, npoly=64, class = "gpc.poly")
    print(disc3)
    plot(disc3, add=TRUE, poly.args=list(border=4))
}

## if one only wants to _draw_ a circle without an object behind
symbols(0, 0, circles=5, inches=FALSE, add=TRUE, fg=5)

surveillance

Temporal and Spatio-Temporal Modeling and Monitoring of Epidemic Phenomena

v1.19.1
GPL-2
Authors
Michael H<f6>hle [aut, ths] (<https://orcid.org/0000-0002-0423-6702>), Sebastian Meyer [aut, cre] (<https://orcid.org/0000-0002-1791-9449>), Michaela Paul [aut], Leonhard Held [ctb, ths], Howard Burkom [ctb], Thais Correa [ctb], Mathias Hofmann [ctb], Christian Lang [ctb], Juliane Manitz [ctb], Andrea Riebler [ctb], Daniel Saban<e9>s Bov<e9> [ctb], Ma<eb>lle Salmon [ctb], Dirk Schumacher [ctb], Stefan Steiner [ctb], Mikko Virtanen [ctb], Wei Wei [ctb], Valentin Wimmer [ctb], R Core Team [ctb] (A few code segments are modified versions of code from base R)
Initial release
2021-03-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.