相关疑难解决方法(0)

确定两个矩形是否相互重叠?

我正在尝试编写一个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)

c++ algorithm geometry rectangles overlap

320
推荐指数
7
解决办法
24万
查看次数

一种简单的多边形交叉算法

我正在寻找一种非常简单的算法来计算多边形交叉/裁剪.也就是说,给定的多边形P,Q我想找到的多边形T被包含在PQ,我希望T是最大的所有可能的多边形中.

我不介意运行时间(我有一些非常小的多边形),我也可以得到一个近似的多边形交叉点(也就是说,一个点数较少的多边形,但它仍包含在多边形的交叉点中).

但对我来说,算法将是简单的(更便宜的测试)并且最好是短(更少的代码)对我来说非常重要.

编辑:请注意,我希望获得一个代表交叉点的多边形.对于两个多边形是否相交的问题,我不需要一个布尔答案.

math geometry 2d polygon

63
推荐指数
6
解决办法
10万
查看次数

标签 统计

geometry ×2

2d ×1

algorithm ×1

c++ ×1

math ×1

overlap ×1

polygon ×1

rectangles ×1