total area of intersecting rectangles

前端 未结 6 1249
余生分开走
余生分开走 2020-12-23 09:43

I need an algorithm to solve this problem: Given 2 rectangles intersecting or overlapping together in any corner, how do I determine the total area for the two rectangles wi

6条回答
  •  渐次进展
    2020-12-23 10:24

    The coordinates of intersection are correct if the origin (0,0) is placed at the bottom-left of the reference system.

    In image processing, where the origin (0,0) is usually placed at the top-left of the reference system, the coordinates bottom and top of intersection would be:

    bottom = min(r1.bottom, r2.bottom)
    top = max(r1.top, r2.top)
    

提交回复
热议问题