我正在尝试编写一个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) 以下枚举定义如下:
public enum Direction
{
North,
South,
East,
West,
Northeast,
Northwest,
Southeast,
Southwest,
Undefined
}
Run Code Online (Sandbox Code Playgroud)
给定二维空间中的两组坐标,我想确定从第2点到第1点的相对基数方向.
例子:
我目前的方法涉及一系列条件,即
if (P1.X == P2.X)
{
// either North, South or Undefined
if (P1.Y < P2.Y)
return Direction.South;
else if (P1.Y > P2.Y)
return Direction.North,
else
return Direction.Undefined;
}
else if (P1.Y == P2.Y)
{
...
}
else
{
...
}
Run Code Online (Sandbox Code Playgroud)
我正在寻求更短,更优雅的解决方案.