I'd kill for a dozen comments, esp. if a goal is to educate students. 498 lines would still be impressive.
Better than my 10-second explanation: https://lodev.org/cgtutor/raycasting.html
Interesting note about this technique: you get perspective correct texturing for free. "Real" 3D rendering usually had to cope with affine texturing due to performance costs until dedicated hardware for it came along.