Raw File
disc.R
#
# disc.R
#
# $Revision: 1.3 $ $Date: 2006/10/17 08:48:29 $
#
#

disc <- function(radius=1, centre=c(0,0), ..., mask=FALSE, npoly=128) {
  stopifnot(length(centre) == 2)
  stopifnot(length(radius) == 1)
  stopifnot(radius > 0)
  stopifnot(length(npoly) == 1)
  stopifnot(npoly > 2)
  if(!mask) {
    theta <- seq(0, 2*pi, length=npoly+1)[-(npoly+1)]
    x <- centre[1] + radius * cos(theta)
    y <- centre[2] + radius * sin(theta)
    W <- owin(poly=list(x=x, y=y))
  } else {
    B <- owin(c(-1,1),c(-1,1))
    B <- as.mask(B, ...)
    indic <- function(x,y,x0,y0,r) ifelse((x-x0)^2 + (y-y0)^2 < r^2, 1, 0)
    IW <- as.im(indic, B, x0=centre[1], y0=centre[2], r=radius)
    W <- levelset(IW, 1, "==")
  }
  return(W)
}

  
back to top