# How to create subdivisions on grids?

**URL:** https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065
**Category:** New to Julia
**Tags:** agents
**Created:** [August 11, 2024, 5:28pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065 "2024-08-11T17:28:49Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![JCaro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcaro/32/209617_2.png) [@JCaro](https://discourse.julialang.org/u/JCaro)
#### Post date: [August 11, 2024, 5:28pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/1 "2024-08-11T17:28:49Z")

</div>

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  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/b/1b367a82bced506643f7600dc28328da9d16243f.png)

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [August 11, 2024, 7:13pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/2 "2024-08-11T19:13:40Z")

</div>

What’s the question here?

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [August 11, 2024, 7:16pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/3 "2024-08-11T19:16:24Z")

</div>

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.

```julia
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)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/7/47205f736903cbe9ca2f5b18cb491235f9d804b3.png)

See the docs and e.g. [Cellular Biology · DelaunayTriangulation.jl](https://juliageometry.github.io/DelaunayTriangulation.jl/stable/applications/cell_simulations/) for another Voronoi example with simulations.

---

<div class="post-metadata">

### Author: ![JCaro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcaro/32/209617_2.png) [@JCaro](https://discourse.julialang.org/u/JCaro)
#### Post date: [August 11, 2024, 7:22pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/4 "2024-08-11T19:22:31Z")

</div>

how to make subdivision in a Agents.GridSpace objects. thats the deal. or make a space that i could subdivide

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [August 12, 2024, 9:01am UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/5 "2024-08-12T09:01:15Z")

</div>

> [@JCaro](#):
>
> how to make subdivision in a Agents.GridSpace objects

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?

---

<div class="post-metadata">

### Author: ![JCaro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcaro/32/209617_2.png) [@JCaro](https://discourse.julialang.org/u/JCaro)
#### Post date: [August 12, 2024, 1:31pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/6 "2024-08-12T13:31:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [August 12, 2024, 1:51pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/7 "2024-08-12T13:51:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [August 12, 2024, 3:44pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/8 "2024-08-12T15:44:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![JCaro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcaro/32/209617_2.png) [@JCaro](https://discourse.julialang.org/u/JCaro)
#### Post date: [August 12, 2024, 4:10pm UTC](https://discourse.julialang.org/t/how-to-create-subdivisions-on-grids/118065/9 "2024-08-12T16:10:22Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/1/2/12e3b03aad4e33f5d4698783dac6b852be760602.jpeg)
