Search code examples
pythonmatlabgeometryvoronoi

Interpret 3D Voronoi results in MATLAB or Python


I have a question regarding constructing 3d Voronoi polygons within a boundary in either MATLAB or Python.

With vertices

[5,5,5],
[2,2,2],
[8,2,2],
[2,8,2],
[8,8,2],
[2,2,8],
[8,2,8],
[2,8,8],
[8,8,8]

and the boundaries [0,0,0] and [10,10,10]

I expect to get

enter image description here

Here's a working example, note that I added 8 nodes to define the corners of the cube.

import pyvoro
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

listResult=pyvoro.compute_voronoi(
  [[5,5,5],
   [2,2,2],
   [8,2,2],
   [2,8,2],
   [8,8,2],
   [2,2,8],
   [8,2,8],
   [2,8,8],
   [8,8,8]], # point positions
  [[0.0, 10.0], [0.0, 10.0], [0.0, 10.0]], # limits
  1.0, # block size
)

dicResult = listResult[0]

Now the vertices from pyvoro are as follows

[[5.0, 5.0, 9.5], 
[5.0, 5.0, 0.50], 
[5.0, 9.5, 5.0], 
[9.5, 5.0, 5.0], 
[0.50, 5.0, 5.0], 
[5.0, 0.50, 5.0]]

faces

[{'adjacent_cell': 4, 'vertices': [1, 3, 2]}, 
{'adjacent_cell': 2, 'vertices': [1, 5, 3]}, 
{'adjacent_cell': 1, 'vertices': [1, 4, 5]}, 
{'adjacent_cell': 3, 'vertices': [1, 2, 4]}, 
{'adjacent_cell': 8, 'vertices': [2, 3, 0]}, 
{'adjacent_cell': 7, 'vertices': [2, 0, 4]},
{'adjacent_cell': 6, 'vertices': [3, 5, 0]}, 
{'adjacent_cell': 5, 'vertices': [4, 0, 5]}]

adjacency

[[2, 4, 5, 3], 
[3, 5, 4, 2], 
[3, 1, 4, 0], 
[0, 5, 1, 2], 
[2, 1, 5, 0], 
[0, 4, 1, 3]]

How do I

  • calculate the boundary vertices (there are only 6 internal vertices but 32 vertices in total)
  • Form the five polyhedrons
  • Extract the edges

Solution

  • Your understanding of the boundary is wrong. In your example, you have site in all eight corners and in the center, and the boundary.

    Just passing a single site results in a trivial voronoi. All points are closest to this size, thus a single region (a cube) fills up everything. This is what pyvoro produced.