Report the distances between agents and agents2.

NLdist(agents, agents2, world, torus = FALSE, allPairs = FALSE)

# S4 method for matrix,matrix
NLdist(agents, agents2, world, torus = FALSE,
  allPairs = FALSE)

Arguments

agents

Matrix (ncol = 2) with the first column "pxcor" and the second column "pycor" representing the patches coordinates, or

AgentMatrix object representing the moving agents.

agents2

Matrix (ncol = 2) with the first column "pxcor" and the second column "pycor" representing the patches coordinates, or

AgentMatrix object representing the moving agents, or

Matrix (ncol = 2) with the first column "x and the second column "y" representing locations coordinates.

world

WorldMatrix or worldArray object.

torus

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

allPairs

Logical. Only relevant if the number of agents/locations in agents and in agents2 are the same. If allPairs = FALSE, the distance between each agents with the corresponding agents2 is returned. If allPairs = TRUE, a full distance matrix is returned. Default is allPairs = FALSE.

Value

Numeric. Vector of distances between agents and agents2 if agents and/or agents2 contained one agent/location, or if agents and agents2 contained the same number of agents/locations and allPairs = FALSE, or

Matrix of distances between agents (rows) and agents2 (columns) if agents and agents2 are of different lengths, or of same length and allPairs = TRUE.

Details

Distances from/to a patch are measured from/to its center.

If torus = FALSE, world does not need to be provided.

If torus = TRUE, a distance around the sides of the world is reported only if smaller than the one across the world.

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#distance

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

Examples

w1 <- createWorld(minPxcor = 0, maxPxcor = 9, minPycor = 0, maxPycor = 9) NLdist(agents = patch(w1, 0, 0), agents2 = patch(w1, c(1, 9), c(1, 9)))
#> [1] 1.414214 12.727922
NLdist(agents = patch(w1, 0, 0), agents2 = patch(w1, c(1, 9), c(1, 9)), world = w1, torus = TRUE)
#> [1] 1.414214 1.414214
t1 <- createTurtles(n = 2, coords = randomXYcor(w1, n = 2)) NLdist(agents = t1, agents2 = patch(w1, c(1,9), c(1,9)), allPairs = TRUE)
#> [,1] [,2] #> [1,] 7.744483 7.843238 #> [2,] 6.571559 6.133327