Learn R Programming

polyCub (version 0.2-0)

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: "gpc.poly", "owin", or "Polygon".

Usage

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

Arguments

center
numeric vector of length 2 (center coordinates of the circle).
r
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'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.

See Also

disc in package spatstat.

Examples

Run this code
## 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")
disc3 <- discpoly(c(0,0), 5, npoly=64, class = "gpc.poly")

## Look at the results
library("spatstat") # for the "owin" print- and plot-methods
print(disc1)
plot(disc1, axes=TRUE, main="", border=2)

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

library("rgeos") # for the "gpc.poly" print- and plot-methods
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)

Run the code above in your browser using DataLab