centroid.owin(w, as.ppp = FALSE)
ppp
object)x, y
, or a point pattern (of class
ppp
) consisting of a single point, giving the coordinates of the
centroid of the window w
.w
is computed.
The centroid (``centre of mass'')
is the point whose $x$ and $y$ coordinates
are the mean values of the $x$ and $y$ coordinates
of all points in the window. The argument w
should be a window (an object of class
"owin"
, see owin.object
for details)
or can be given in any format acceptable to as.owin()
.
The calculation uses an exact analytic formula for the case of polygonal windows.
Note that the centroid of a window is not necessarily inside
the window, unless the window is convex.
If as.ppp=TRUE
and
the centroid of w
lies outside w
,
then the window of the returned point pattern
will be a rectangle containing the
original window (using as.rectangle
.
owin
,
as.owin
w <- owin(c(0,1),c(0,1))
centroid.owin(w)
# returns 0.5, 0.5
data(demopat)
w <- as.owin(demopat)
# an irregular window
cent <- centroid.owin(w, as.ppp = TRUE)
plot(cent)
# plot the window and 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