Two Rectangles intersection

后端 未结 7 2106
北海茫月
北海茫月 2020-11-27 16:39

I have two rectangles characterized by 4 values each :

Left position X, top position Y, width W and height H:

7条回答
  •  Happy的楠姐
    2020-11-27 17:05

    if( X1<=X2+W2 && X2<=X1+W1 && Y1>=Y2-H2 && Y2>=Y1+H1 ) Intersect

    In the question Y is the top position..

    Note: This solution works only if rectangle is aligned with X / Y Axes.

提交回复
热议问题