具体问题是:
N行,每一行包含两个整数。第一条线包含了依顺时针或逆时针顺序排列的多边形的第一顶点-- I。请注意,一个侧面有可能出现两个以上的顶点,如下所示:

现在你需要判断多边形的顶点是顺时针的还是逆时针的?
c++代码是:
struct Node
{
int x, y;
Node operator-(Node node) const
{
Node t;
t.x = x - node.x;
t.y = y - node.y;
return t;
}
int operator*(Node node) const // I konow this is Cross-Product
{
return x * node.y - y * node.x;
}
}node[1000];
for (int i = 0; i < n; i++)
scanf("%d %d", &node[i].x, &node[i].y);
int tmp = 0;
node[n].x = node[0].x, node[n].y = node[0].y;
for (int i = 0; i < n; i++)
tmp += (node[i] * node[i + 1]);
if (tmp > 0)
it is counterclockwise order;但我不明白密码,谁能证明呢?
发布于 2017-12-03 11:01:50
鞋带公式将给出任意多边形的有向区域。通过检查它的符号,您就可以确定它的方向。您所拥有的代码确实计算了两倍的面积,但由于符号才是最重要的,这是不相关的。
https://stackoverflow.com/questions/47617622
复制相似问题