I'm looking for a simple way of calculating the area between two straight lines in a -1 to +1 square surface, the shaded fields in the plot below:
My first thought was to calculate the difference of the integrals of the two lines. But I had to split it into two parts (left and right of the intersection) since I wanted the total area, not the upper area minus the lower area. When finished, I realized that the integrals included a triangular area below y = -1. I'm only interested in the area bounded by -1 <= x <= +1 and -1 <= y <= +1.
My second thought was to calculate the area of the two triangles using the intersection point and the points where the lines exit the bounded area. But there are several cases to handle here, for each triangle:
- Both lines exit the area to the left or right.
- Both lines exit the area to the top or bottom.
- One line exits to the right or left and the other one to the top or bottom.
- The lines do not intersect.
I guess there is probably a much simpler solution that I haven't thought of.