我正在尝试编写一个C++程序,它从用户那里获取以下输入来构造矩形(2到5之间):高度,宽度,x-pos,y-pos.所有这些矩形将平行于x轴和y轴存在,即它们的所有边都将具有0或无穷大的斜率.
我试图实现这个问题中提到的但我没有太多运气.
我目前的实现如下:
// Gets all the vertices for Rectangle 1 and stores them in an array -> arrRect1
// point 1 x: arrRect1[0], point 1 y: arrRect1[1] and so on...
// Gets all the vertices for Rectangle 2 and stores them in an array -> arrRect2
// rotated edge of point a, rect 1
int rot_x, rot_y;
rot_x = -arrRect1[3];
rot_y = arrRect1[2];
// point on rotated edge
int pnt_x, pnt_y;
pnt_x = arrRect1[2];
pnt_y = arrRect1[3]; …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种算法来检测两个矩形是否相交(一个是任意角度,另一个只有垂直/水平线).
测试一个角落是否在另一个ALMOST中.如果矩形形成十字形状,则失败.
避免使用线条的斜率似乎是一个好主意,这需要垂直线条的特殊情况.