我正在尝试编写一个C++程序,从用户那里获取以下输入来构建矩形(2到5个):高度、宽度、x位置、y位置。所有这些矩形都将与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];
// test point, a from rect 2
int tst_x, tst_y;
tst_x = arrRect2[0];
tst_y = arrRect2[1];
int value;
value = (rot_x * (tst_x - pnt_x)) + (rot_y * (tst_y - pnt_y));
cout << "Value: " << value;
然而,我不太确定我是否正确实现了我链接的算法,或者如果我确实实现了它,该如何解释它?
有什么建议吗?