# Raycaster calculation question

I am following this tutorial https://lodev.org/cgtutor/raycasting.html 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.

## 1 Answer

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

• 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? – Felsir Jan 28 '19 at 11:53