0
\$\begingroup\$

I am following this tutorial https://lodev.org/cgtutor/raycasting.html

enter image description here

When deriving deltaDistX geometrically you get, with Pythagoras, the formula "sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX))", but this can be simplified to abs(1 / rayDirX). [thanks to Artem for spotting this simplification] Similarly, deltaDistY is "sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY))" which can be simplified to abs(1 / rayDirY). The variable perpWallDist will be used later to calculate the length of the ray.

In the calculation that involves Pythagoras, why is a "+1" involved? I thought the equation was a^2+b^2=c^2? I feel dense... Also, I do not understand how the simplification to abs(1/rayDirX) works.

\$\endgroup\$
1
\$\begingroup\$

I believe what is going on here is a rescale of the triangle. See: https://betterexplained.com/articles/rescaling-the-pythagorean-theorem/

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think you’re correct- however link only answers are not preferred (in the event the connecting page gets taken down). Perhaps you can write a short description of what the purpose of the calculation is? \$\endgroup\$ – Felsir Jan 28 '19 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.