On XY plane, you are given upper left corner coordinates of two equal sized rectangles. Find the intersection percentage of the rectangles.
Question: Write a program that is going to read two rectangle information and find the intersection percentage.
Input specification
You will be first given the width (w) and height (h) of the rectangles. Then upper left coordinates (x, y) of the two rectangles are given in the following two lines where 0 <= (x, y) <= 10000 and 1 <= (w, h) <= 100.
Output specification
Show a floating point number with 3 decimal places that is the intersection percentage to the second rectangle.
First rect in the example has upper left in (1,4). It is 4 wide, so its upper right is in (5,4).
Height 3 means lower left at (1,1) and lower right at (5,1).
The second rect is thus:
(3,5) (7,5)
(3,2) (7,2)
The intersection is 2 wide (5-3==2) and 2 high (4-2).
Area of intersection / area of rectangle = (2*2) / (4*3) = 1/3
Integer division produces only integers. Luckily, you need to produce percentage and can thus use 100.0.
Note:
1 / 3 * 100.0 == 0.0
100.0 * 1 / 3 == 33.33333