library(spatstat)
  w <- owin(c(0,1),c(0,1))
  centroid.owin(w) 
  # returns 0.5, 0.5
  data(demopat)
  w <- demopat$window
  # an irregular window
  plot(w)
  # plot the window
  points(centroid.owin(w))
  # mark its centroid
  wapprox <- as.mask(w)
  # pixel approximation of window
  points(centroid.owin(wapprox))
  # should be indistinguishable
  <testonly>centroid.owin(w)
  centroid.owin(wapprox)</testonly>Run the code above in your browser using DataLab