Search code examples
algorithm3dline

3d "Greedy" Bresenham's Line Algorithm


Is there a fast (i.e. not incremental step) algorithm to find all voxels that a line intersects in 3d space?

I compare to Bresenham's line algorithm, but I want it to be "greedy" such that it doesn't just form a line, but provides every single intersection. It also must be applicable to 3d space.

The purpose is for ray tracing, but I was hoping for a 3d grid I wouldn't have to do a method where I step a tiny bit, look at the cube the point is on, then step forward another tiny bit, until I reach the other end of the line.


Solution

  • Yes, there is Amanatides and Woo article "A Fast Voxel Traversal Algorithm for Ray Tracing" for 2D and 3D cases.

    In general it is like your idea Find the point the line exits the cube via line-intersecting-plane math

    Example of implementation

    2D case example:

    enter image description here