【发布时间】:2018-05-28 06:38:38
【问题描述】:
我有四个坐标:x,y,width=w,height=h,我有两个矩形,坐标如下:
r1.x=2,r1.y=3,r1.w=5,r1.h=6;
r2.x=0, r2.y=7,r2.w=-4,r4.h=2
如何观察这个路口是空的。
到目前为止我所做的是:
rectangle intersection (rectangle r1, rectangle r2){
r1.x=max(r1.x,r2.x);
r1.y=max(r1.y,r2.y);
r1.w=min(r1.w,r2.w);
r1.h=min(r1.h,r2.h);
return r1;
}
我认为上面的代码是在有交叉路口时使用的,但是当交叉路口为空时我不知道。另外,当没有交叉点时,我想打印一条消息“空”。
谢谢!
【问题讨论】:
-
除非您显示的代码是pseudocode,否则请用您使用的语言标记您的问题。请read about how to ask good questions,我也建议你阅读this Stack Overflow question checklist。
-
有时在纸上画出来会有所帮助。检查没有交叉点很容易。
标签: c++ mathematical-optimization procedure rectangles