Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 查找两个矩形是否重叠_Algorithm_Math_Rectangles_Overlapping - Fatal编程技术网

Algorithm 查找两个矩形是否重叠

Algorithm 查找两个矩形是否重叠,algorithm,math,rectangles,overlapping,Algorithm,Math,Rectangles,Overlapping,我试图找出两个矩形是否相互重叠。我将以下矩形表示为[x1,x2]x[y1,y2] Rect 1 = [0.0, 1.0] x [0.0, 1.0] Rect 2 = [0.7, 1.2] x [0.9, 1.5] 我只需要一个可以实现的伪代码来查找矩形是否相互重叠。if((Rect1.topLeft.x>Rect2.bottomRight.x)|(Rect1.bottomRight.xRect2.bottomRight.y)|(Rect1.bottomRight.yb.x2 | | b.x1>

我试图找出两个矩形是否相互重叠。我将以下矩形表示为
[x1,x2]x[y1,y2]

Rect 1 = [0.0, 1.0] x [0.0, 1.0]
Rect 2 = [0.7, 1.2] x [0.9, 1.5]
我只需要一个可以实现的伪代码来查找矩形是否相互重叠。

if((Rect1.topLeft.x>Rect2.bottomRight.x)|(Rect1.bottomRight.xRect2.bottomRight.y)|(Rect1.bottomRight.y  if ((Rect1.topLeft.x  >  Rect2.bottomRight.x) || (Rect1.bottomRight.x  <  Rect2.topLeft.x)  || (Rect1.topLeft.y > Rect2.bottomRight.y) || (   Rect1.bottomRight.y  <  Rect2.topLeft.y)):
            Then NOT OVERLAPPING
  else:
            OVERLAPPING
那就不重叠了 其他: 重叠
如果矩形表示为
[x1,x2]x[y1,y2]

if(a.x1>b.x2 | | b.x1>a.x2)返回false;//检查x轴
如果(a.y1>b.y2 | b.y1>a.y2)返回false;//检查y轴
返回true;

条件
a.x1>b.x2
检查
a
的左边框是否位于
b
的右边框的右侧,如果是这样,则矩形不重叠。其他三个条件是相似的。

我认为答案是这样的。@sasmith提供的答案非常有效。谢谢虽然此代码可能会回答该问题,但提供有关此代码为什么和/或如何回答该问题的附加上下文可提高其长期价值。