# Vector / trigonometry question

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.

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?

-