I am going through code snippets that calculate the x-intersection point between the line parallel to the x-ais and an arbitrary line between points (x1,y1) and (x2,y2). The code snippet does the following:
double t = (x2 - x1)/(y2 - y1);
xDbl = (static_cast(yPos) - y1) * t + x1;
I am having difficulty to understand the calculation of t, is it rise over run ? Some mathematical reference to the above snippet would be very helpful.
Thanks
Line passing through two points $(x_1, y_1)$ and $(x_2, y_2)$ is given by:
$$y-y_1 = \dfrac{y_1-y_2}{x_1 - x_2}\times (x-x_1)\ \ \ \ \ \ \ ... \rm (i)$$
for point of intersection with $y = k$, put $y = k$ in above equation.
$$k-y_1 = \dfrac{y_1-y_2}{x_1 - x_2}\times (x-x_1)$$
Solving for $x$ gives the x-coordinate. Substitute the value in $\rm Eqn \ (i)$ to find y coordinate.