Learn R Programming

surveillance (version 1.5-4)

discpoly: Generate a Polygon Representing a Disc/Circle (in Planar Coordinates)

Description

This functions generates a circle/disc represented as a polygon of one of three possible data classes: "gpc.poly", "owin", and "Polygon".

Usage

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

Arguments

center
numeric vector of length two. Center coordinates of the circle.
r
numeric scalar. Radius of the circle.
npoly
integer. Number of edges of the polygonal approximation to the circle.
class
Which class of polygon should be generated? For spatstat's "owin" class, the disc function is used.
hole
logical. hole flag of the polygon.

Value

  • Polygon of class class representing a circle/disc with npoly edges accuracy.

See Also

disc in package spatstat.

Examples

Run this code
# Construct circle 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")

library("spatstat")
print(disc1)
plot(disc1, axes=TRUE, main="", border=2)

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

if (require("gpclib")) {
    oopt <- surveillance.options(gpclib=TRUE)
    disc3 <- discpoly(c(0,0), 5, npoly=64, class = "gpc.poly")
    print(disc3)
    plot(disc3, add=TRUE, poly.args=list(border=4))
    surveillance.options(oopt)
}

# 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