I am following this tutorial for a Wolfenstein 3D engine. https://lodev.org/cgtutor/raycasting.html
Here is the relevant image from the tutorial:
I cannot figure out how dividing by rayDirX or rayDirY causes the distance calculation to work. The explanation given is about halfway down the page, right above this text if you search for it: "Calculate distance projected on camera direction".