# Discrete line inside a 3D matrix

First of all a little premise: I'm following this tutorial on YouTube for procedural 2d cave generation in unity using cellular automata and I'm extending it in order to make caves in all three dimensions. With this approach, caves are based on a 3d matrix where if a cell value is 1 it is a wall and if 0 it is an empty space. The "rooms" created, after being logically connected, need to be "physically" connected by making a path of zeros in the 3d matrix and the tutorial explains how to do this in 2d.

Can you, please, suggest me the approach on how to draw a discrete line (of zeros in this case), in a 3d matrix, that goes from point A to point B?

I'll attach a screen of a map example where rooms are drawn with cubes and red lines are the logical connections.

• Bresenham's line drawing algorithm, originally in 2D, has been revised in many places with a 3D version. – Patrick Hughes Feb 5 at 0:02
• I would bet that a DDA line algorithm could also work in 3D. – user1118321 Feb 5 at 6:57
• Bresenham is more efficient that DDA. – Patrick Hughes Feb 5 at 18:26