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?