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
What’s the question here?
It’s hard to tell what you want exactly, but DelaunayTriangulation.jl can be used for creating Voronoi tessellations and clipping them to a rectangular boundaries. You’ll have to clarify if you need more than that.
e.g.
using DelaunayTriangulation, CairoMakie
# The tessellation
points = rand(2, 20)
tri = triangulate(points)
vorn = voronoi(tri)
# Clip to [0, 1] × [0, 1]
bounding_box = (0.0, 1.0, 0.0, 1.0)
clipped_coords = Vector{Vector{NTuple{2, Float64}}}(undef, num_polygons(vorn))
for i in each_polygon_index(vorn)
clipped_coords[i] = get_polygon_coordinates(vorn, i, bounding_box)
end
# Plotting
fig, ax, sc = poly(clipped_coords, strokewidth = 4, color = :white)
See the docs and e.g. Cellular Biology · DelaunayTriangulation.jl for another Voronoi example with simulations.
how to make subdivision in a Agents.GridSpace objects. thats the deal. or make a space that i could subdivide
You can’t. You’d need to make a new space for this.
But it appears to me that you want to subdivide the agents themselves, not the space? If each color is an agent in your original plot, you probably want to use a ContinuousSpace
and make the agents themselves have an area property, and a shape property, and subdivide the agents themselves?
no, i want a well designed random subdivision, because every area have a meaning for the agents. After the segmentation, every area gets a value that means something for the agents, who can move freely in the space.
I’ve never used Agents.jl so maybe this is not feasible, but is it not possible to use the approach I gave together with your simulations in Agents.jl? Is it easy to find where an agent lies in the Voronoi diagram to get the area of the associated region.
This is the solution. It is very feasible to do this in Agents.jl by utilizing additional packages. However, you need to switch to ContinuousSpace
@JCaro . My recommendation would be to make the Triangulation a property of the model and use the agent positions to find out which tesselation they are in. A model_step!
function can update the Delunay Triangulation at each step if agent actions affect it.