We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
今天在工作上遇到了需要判断一个给定的任意多边形是逆时针还是顺时针的问题。 如果是凸多边形,那看任意两个边的向量做一个叉乘就知道方向了。考虑到有可能是凹多边形,所以我判断了所有相邻的边的向量叉乘,然后取大于一般的方向。具体代码如下:
//判断多边形是逆时针还是顺时针, true:逆时针
bool isAntiClock(vector<Vec2d>& polygon) { int sz = polygon.size(); int greaterC = 0, lessC = 0; for (int i = 0; i < polygon.size(); i++) { Vec2d a = polygon[i]; Vec2d b = polygon[(i+1)%sz]; Vec2d c = polygon[(i+2)%sz]; if ((b-a)/(c-b) > 0) greaterC ++; else lessC ++; } if (greaterC > lessC) { return true; } else return false; }
之后,我查了一下网上的资料,用的方法更科学高效,是找到多边形最左下角的节点,然后看该节点相邻两个边的向量方向。因为是最左下角,所以一定是一个凸的节点,顿时觉得自己low爆儿了。
The text was updated successfully, but these errors were encountered:
是否一定要左下角呢?最左边的点似乎就可以了
Sorry, something went wrong.
代码测试了下好像没有办法监测出来呀,我用了另外的一种方法试了试 ok https://blog.csdn.net/QLU_minoz/article/details/89185726 多多指教
No branches or pull requests
今天在工作上遇到了需要判断一个给定的任意多边形是逆时针还是顺时针的问题。
如果是凸多边形,那看任意两个边的向量做一个叉乘就知道方向了。考虑到有可能是凹多边形,所以我判断了所有相邻的边的向量叉乘,然后取大于一般的方向。具体代码如下:
//判断多边形是逆时针还是顺时针, true:逆时针
之后,我查了一下网上的资料,用的方法更科学高效,是找到多边形最左下角的节点,然后看该节点相邻两个边的向量方向。因为是最左下角,所以一定是一个凸的节点,顿时觉得自己low爆儿了。
The text was updated successfully, but these errors were encountered: