Determine if two rectangles overlap each other?

前端 未结 23 862
礼貌的吻别
礼貌的吻别 2020-11-22 04:09

I am trying to write a C++ program that takes the following inputs from the user to construct rectangles (between 2 and 5): height, width, x-pos, y-pos. All of these rectang

23条回答
  •  时光说笑
    2020-11-22 05:01

    I have a very easy solution

    let x1,y1 x2,y2 ,l1,b1,l2,be cordinates and lengths and breadths of them respectively

    consider the condition ((x2

    now the only way these rectangle will overlap is if the point diagonal to x1,y1 will lie inside the other rectangle or similarly the point diagonal to x2,y2 will lie inside the other rectangle. which is exactly the above condition implies.

提交回复
热议问题