Report the coordinates of the patches at the given [x, y] locations.

patch(world, x, y, duplicate = FALSE, torus = FALSE, out = FALSE)

# S4 method for worldNLR,numeric,numeric
patch(world, x, y, duplicate = FALSE,
  torus = FALSE, out = FALSE)

Arguments

world

WorldMatrix or worldArray object.

x

Numeric. Vector of x coordinates. Must be of same length as y.

y

Numeric. Vector of y coordinates. Must be of same length as x.

duplicate

Logical. If more than one location [x, y] fall into the same patch and duplicate == TRUE, the patch coordinates are returned the number of times the locations. If duplicate == FALSE, the patch coordinates are only returned once. Default is duplicate == FALSE.

torus

Logical to determine if the world is wrapped. Default is torus = FALSE.

out

Logical. If out = FALSE, no patch coordinates are returned for patches outside of the world's extent, if out = TRUE, NA are returned. Default is out = FALSE.

Value

Matrix (ncol = 2) with the first column "pxcor" and the second column "pycor" representing the patches coordinates at [x, y].

Details

If a location [x, y] is outside the world's extent and torus = FALSE and out = FALSE, no patch coordinates are returned; if torus = FALSE and out = TRUE, NA are returned; if torus = TRUE, the patch coordinates from a wrapped world are returned.

References

Wilensky, U. 1999. NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University. Evanston, IL.

See also

https://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch

Examples

w1 <- createWorld(minPxcor = 0, maxPxcor = 9, minPycor = 0, maxPycor = 9) patch(world = w1, x = c(0, 9.1, 8.9, 5, 5.3), y = c(0, 0, -0.1, 12.4, 12.4))
#> pxcor pycor #> [1,] 0 0 #> [2,] 9 0
patch(world = w1, x = c(0, 9.1, 8.9, 5, 5.3), y = c(0, 0, -0.1, 12.4, 12.4), duplicate = TRUE)
#> pxcor pycor #> [1,] 0 0 #> [2,] 9 0 #> [3,] 9 0
patch(world = w1, x = c(0, 9.1, 8.9, 5, 5.3), y = c(0, 0, -0.1, 12.4, 12.4), torus = TRUE)
#> pxcor pycor #> [1,] 0 0 #> [2,] 9 0 #> [3,] 5 2
patch(world = w1, x = c(0, 9.1, 8.9, 5, 5.3), y = c(0, 0, -0.1, 12.4, 12.4), torus = TRUE, duplicate = TRUE)
#> pxcor pycor #> [1,] 0 0 #> [2,] 9 0 #> [3,] 9 0 #> [4,] 5 2 #> [5,] 5 2