I need to work on a simulation and i want to make a gridspace and sub-divide it, using random points in the grid and their respectivly voronoi polygons. Can someone give some directions on how/how not do it??

a image of my idea

I need to work on a simulation and i want to make a gridspace and sub-divide it, using random points in the grid and their respectivly voronoi polygons. Can someone give some directions on how/how not do it??

a image of my idea

You could start by working through the tutorials here, perhaps.

I made a short script that does something similar a while back. It’s not at all optimized, but can produce the below image using the Random, Plots, and Colors packages.

Its implementation really comes down to creating a list of empty cells, dividing up the grid into very small intervals, computing the distance from each grid point to all other points, finding the closest random point, and storing it to the corresponding cell. The main calculation is the following:

```
distances = [sqrt((px - x)^2 + (py - y)^2) for (px, py) in points]
closest_point = argmin(distances)
if closest_point == length(all_cells) + 1
push!(current_cell, (x, y))
end
```

Where px/py are the random points and x/y are the small intervals of your grid. Feel free to message me if you’d like more details on its implementation though.

If you’re looking for something more optimized, I’d look at the DelauneyTriangulation.jl package already mentioned or the VoronoiDelaunay.jl package (which appears to be under maintenance).

1 Like

already working on the segmenytation using discetevoronoi. but using the voronoi-grid as data in the space type-object in the agents.jl is my real deal

There is truly no difference in having this data as a model property instead of somehow having it in the space

CU!

George

If all you care about is creating the diagrams, then it may be quicker to simply run the calculation and color the regions yourself rather than searching for existing packages. My script was only around 50 lines and seems to do everything you wanted in the original prompt: create and subdivide a gridspace, generate random points on that grid, and create a voronoi diagram.

If you tell us more about the goal of the simulation, and why you’d prefer to use agent based modeling like Agents.jl, then maybe we can give more directed advice.

i really want to replicate a ecology paper that predicts certain properties of certain invasive species, and predict the outcomes of using diferents ways to manage it, and they do via ABM. In that simulation, the agents self-replicate (as any living being), and the rate of reproductions depends on where the agent is, in a subdivided grid of polygons. All poligons are rated from 1, as the smaller rate of reproduction ind/seconds to 9 as the bigger rate