An example of a DDA-like algorithm to step through all grid cells that touch a ray and get the cell entry points. This algorithm is useful for many things, such as drawing 2D(/3D) lines or raycasting a 2D(/3D) volume. For example the classic Wolfenstein used a similar algorithm to raycast each vertical line. Also for 3D application voxel volumes/octres could be traversed by using this algorithm.

The example is 2D but to extend it to 3D, you’d need to add the Z-component and basically step the minimum of X, Y and Z on each step (instead of only X or Y as in the 2D case).

Here’s the algorithm running. If you see nothing below, make sure that you have javascripts enabled and have a reasonable recent browser (Internet Explorer 9 or newer, the most recent Chrome, Firefox, Safari etc).