1

Background

I have a 3D scene, and I want to discretize the space of it so that every coordinate (x, y, z) belongs to a specific cell.
Coordinates close to each other belongs to same cells. When I input a coordinate that lies on the surface of one of my tridimensional objects (mainly spheres), I need to retrieve the cell it belongs to.
For those familiar with Reinforcement learning, this operation will be used for Q-Learning, to map states (cells depending on coordinates) to Q-values
This is an example of what i am trying to achieve:

enter image description here

Possible solutions

I know that Voronoi diagram can help in this, but I also read that implementing it from scratch is complicated. I found some libraries in C++ to handle this, but they are mainly Voronoi 2D (CGAL). I don't specifically need Voronoi, I only need to discretize the space in a reasonable way and looking for libraries/implementation for it I stumbled upon Voronoi diagrams.

Question Is there anyone familiar with libraries or a public implementation to achieve this discretization in C++?

Community
  • 1
  • 1
maurock
  • 527
  • 1
  • 7
  • 22

1 Answers1

1

Depending on you requirements, there may be many solutions. The simplest I can think of is to partition your space using a uniform grid. Then, the cell of a point (x,y,z) is simply (floor(x),floor(y),floor(z)). You can scale the coordinates to have get finer grid. If you need to have a single index, use a hash function or index all cells of a finite grid inside a bounding box. No libraries required, but it is not adaptive to the amount of points in an area.

Voronoï diagrams are another possible solution, but they are a lot more complicated to implement if you want the exact shape of all cells. If you only need to find the nearest site point, use Kd-Trees since they are a lot simpler to implement and gives you the information you need. You can find an implementation of both of these algorithms in GEOGRAM, a free and open (you can use it in commercial applications) C++ libraries for doing fast geometric computations. It works quite well and it is easy to use. It is also portable, it works on Linux, Windows, Mac OSX and Android.