The DDA Algorithm, explained interactively
Published on: 2025-05-08 01:59:46
The DDA Algorithm, explained interactively
I've written a number of voxel raytracers, and all of them (all the good ones, at least) use the Digital Differential Analyzer Algorithm for raycasting. I've only ever "implemented" this algorithm once, by copying a reference somewhere. Since then, I've used and re-used that code. But I have something to admit: I've never really understood how it works. I've seen it explained well, explained poorly, explained on video, and still, I just don't get it. It's one of those geometric algorithms that's hard to wrap your head around, at least for me. But recently, I ran into some issues with a raytracer, and I decided to try to fully understand it. And I made this blog post, for others like me.
All code in this article is editable. Examples will update as you modify them.
DDA, in 2D, is an algorithm that iterates over all of the grid squares intersected by a ray. For those who haven't seen the algorithm, it looks like this:
ro.x ro.y rdAngle
If y
... Read full article.