Are we in the same neighborhood? Looking at how 2D adjacencies map to 3D

Rhys Goldstein has had one more excellent article published in Towards Data Science. This is the third - and he says final, I hope he's wrong - article in the series.

Here they are, along with my accompanying posts:

In this latest installment, Rhys explores one particular aspect of what it means to go from a 2D pathfinding environment to one focused on 3D.

When looking at adjacent positions within a 2D grid, it's possible to have 4-, 6-, 8-, 12- and 16-neighborhoods:

2D neighborhoods

These map very differently to 3D, where we end up with 6-, 18-, 26-, 50-, and 74-neighborhoods!

3D neighborhoods

It seems no-one had previously connected the 2D neighborhoods with their 3D equivalents, which was Rhys's goal from this article.

Here they are, one-by-one. Let's start with the rectangular neighborhoods.

A 2D 4-neighborhood is a section of the 3D 6-neighborhood:

Neighbors 6

A 2D 8-neighborhood is a section of the 3D 26-neighborhood:

Neighbors 26

A 2D 16-neighborhood is a section of the 3D 74-neighborhood:

Neighbors 74

Now for the triangular neighborhoods.

A 2D 6-neighborhood is a section of the 3D 18-neighborhood:

Neighbors 18

A 2D 12-neighborhood is a section of the 3D 50-neighborhood:

Neighbors 50

Things get much more complex beyond these first 5, of course. I really don't blame Rhys for stopping there. 🙂

If you're interested in seeing some code that uses these various 3D neighborhoods to solve a visibility problem, be sure to check out the Python source in Rhys's fascinating post.

Leave a Reply

Your email address will not be published. Required fields are marked *