Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

centroid.owin

Centroid of a window


Description

Computes the centroid (centre of mass) of a window

Usage

centroid.owin(w, as.ppp = FALSE)

Arguments

w

A window

as.ppp

Logical flag indicating whether to return the centroid as a point pattern (ppp object)

Details

The centroid of the window 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.

Value

Either a list with components x, y, or a point pattern (of class ppp) consisting of a single point, giving the coordinates of the centroid of the window w.

Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner r.turner@auckland.ac.nz and Ege Rubak rubak@math.aau.dk.

See Also

Examples

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 
  }

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.