# Find out intersection of lines with only edge points

I need to find out the points of intersection of two straight lines/rectangles.

Given following example with sample coordinates:

The red line intersects the black rectangle in two points. I need to find out at which coordinates they intersect. I understand that I can get the angle of a line segment via (coming from a computer based environment):

angle = atan2 (y2 - y1, x2 - x1)


or the distance between two points of the line via

distance = sqrt ( (x2 - x1)² + (y2 - y1)² )


But I don't understand how I could apply this information to find out the coordinates of the two intersection points A and B.

What formula can I use to find out these points?

Use two point form $\frac {(y - y1)}{( x - x1)} = \frac {(y2 - y1)}{(x2 - x1)}$ where x1 = 0.5, y1 = 0.25; and x2 = 1.5, y2 = 1.25 to set up an equation.