Suppose you have the following positive coordinate region below:
In this region we have a rectangle that represents a computer window. As you can see there are also line segments covering the region. I am attempting to try and solve a problem in which I will clip the line segments when they are outside of the window.
For instance, the top left coordinate of the window below would be (20,80), its bottom left coordinate would be (20, 20), its top right coordinate would be (120, 80) and its bottom right coordinate would be (120, 20). Line segment B has a starting coordinate of (55, 65) and an ending coordinate of (90, 90).
If I were to clip segment B, though, it would then have a starting coordinate of (55,65) and an ending coordinate of (76, 80).
Programmatically, how would I go about calculating where the line segment intersects the line segment of the window? Likewise, how would I go about finding that they don't intersect at all like segment E.
Try this.
and
output: