# perpendicular distance to center of square from line in terms of slope

I am trying to find the relationship between the vertical distance (V) from the center of the square to the line to the perpendicular distance (P) from the center of the square to the line in terms of slope.

I know the answer. The vertical distances are related to the perdendicular distances by a factor of such that p=cv where dx=x2-x1 and dy = y2-y1

However I do not know how to find this relationship...can someone step through the math that arrives at this?

In the image I have increased the size of the square. In my problem I am trying to find this relationship for each square in the grid that the line cuts through. Then I can find P at any square on the grid. I believe the relationship should be the same in either case.

-

The relationship arises because the triangle you drew has the same angles as a triangle demonstrating the slope of the line. If you draw a triangle underneath the line with one horizontal side of length $\Delta x$ and one vertical side of length $\Delta y$, that triangle has the same angles, since it has a right angle and the two angles between the vertical lines and the given line are the same.
That means that the ratios of corresponding sides must be the same. The side corresponding to $P$ has length $\Delta x$, and the side corresponding to $V$ is the hypotenuse, which by Pythagoras has length $\sqrt{\Delta x^2 + \Delta y^2}$.