How to find the area of intersecting parts of 2 rectangles in ABAP?

Good day to all! There is such a problem, the solution of which must be written in the ABAP language:

Two rectangles are defined on the plane. Each rectangle is defined by the coordinates of two opposite vertices. Find the intersection area of these rectangles. Remark. The sides of the rectangles are parallel to the coordinate axes.

Input data The first line contains four numbers - the coordinates of the two opposite vertices of the first rectangle. In the second line are written the four numbers are the coordinates of the two opposite vertices of the second rectangle. Rectangles can degenerate into segments and even points. All coordinates are integers from 0 to 40,000.

Tell me in what direction to think and how to solve this problem? There is no experience in AVAR at all.

How high do you think the difficulty level of this task is?

And why couldn't I create an ABAP tag and no one on this forum has created it yet? Is it really such a rare language, that no one is interested in him?

Author: Barmaley, 2017-09-27

1 answers

The algorithm is:

  • r1, r2 = rectangle 1 or 2
  • x, y = the corresponding coordinate
  • l, r, t, b = left, right, top, bottom (y-axis pointing down)
  • res = area of intersection (if not intersect, then 0)
r1x1 r1y1 r1x2 r1y2
r2x1 r2y1 r2x2 r2y2

r1l = min(r1x1, r1x2)
r1r = max(r1x1, r1x2)
r1t = min(r1y1, r1y2)
r1b = max(r1y1, r1y2)

r2l, r2r, r2t, r2b = ...

l = max(r1l, r2l)
r = min(r1r, r2r)
t = max(r1t, r2t)
b = min(r1b, r2b)

res = max(r - l, 0) * max(b - t, 0)
 0
Author: , 2017-09-27 14:26:13