I was reading a programming and found an exercise that asked for calculating the intersection of two lines, according to the following formula:


I know that the formula can be solved by using Cramer's rule, and I actually know how to program it, but the problem is I do not recall how that formula is derived mathematically. Maybe it sounds like a silly question, but does it has something to do with the conversion of a line to the following equation that includes the slope $y=mx+b$?
In your picture, with $(x,y)$ being the desired intersection point, the segment from that point to $(x_1,y_1)$ has the same slope as the segment from $(x_2,y_2)$ to $(x_1,y_1)$, because they're parts of the same line. So $$ \frac{y-y_1}{x-x_1}=\frac{y_2-y_1}{x_2-x_1}. $$ Clear fractions and rearrange terms to get the first of your two equations. The second is obtained the same way, using the other line in the picture.