w <- owin(c(0,1),c(0,1))
centroid.owin(w)
# returns 0.5, 0.5
w <- Window(demopat)
# an irregular window
cent <- centroid.owin(w, as.ppp = TRUE)
wapprox <- as.mask(w)
# pixel approximation of window
if(interactive()) {
plot(cent)
# plot the window and its centroid
points(centroid.owin(wapprox))
# should be indistinguishable
}
# \testonly{
centroid.owin(w)
centroid.owin(wapprox)
# }
Run the code above in your browser using DataLab