total area of intersecting rectangles

前端 未结 6 1218
余生分开走
余生分开走 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:41

    Sorry to come to the party late. I dont know if you are looking language specific : But on iOS its pretty easy :

    CGRectIntersection

    https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGGeometry/#//apple_ref/c/func/CGRectIntersection

    It would give you CGrect that is overlappring by given two rects. if they are not intersecting is would return CGRectIsNull.

    hope this help at least someone. Happy coding

提交回复
热议问题