1
$\begingroup$

I'm checking out this programming tutorial on raycasting at http://lodev.org/cgtutor/raycasting.html and have a probably very simple question about the math used.

I'm having trouble understanding the calcuation of deltaDistX and deltaDistY, which in a square grid are the distances between the x sides or the y sides of each square given a vector of a certain direction moving through them. See the screenshot below.

enter image description here

In the tutorial they are calculated as follows, but without much explanation:

//length of ray from one x or y-side to next x or y-side double deltaDistX = sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX)); double deltaDistY = sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY)); 

Where rayDirY and rayDirX are the direction of a ray moving through the squares.

How do you get these formulas? It looks like pythagorean theorem is part of it, but somehow there's division involved here. Can anyone clue me in as to what mathematical knowledge I'm missing here, or "prove" the formula by showing how it's derived?

1 Answers 1

0

The question was answered at the game dev section where I asked the same question.

https://gamedev.stackexchange.com/questions/45013/raycasting-tutorial-vector-math-question/45025#45025

Don't know if I should delete this thread or not since it's a duplicate. I'll keep it here in case anyone's interested and leave that up to the mods!