我怎样才能简化一个复杂的多边形? [英] How could I simplify a complex polygon?
本文介绍了我怎样才能简化一个复杂的多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我想要做的事情:
我将以JavaScript结尾,但是任何形式的解决方案都是好的(语言,算法或简单的英语)。
我会使用与手工绘制多边形时相同的启发式(这可能不是计算多边形最有效的数学算法,但可能是最容易理解/实现的)。- 从一个点开始
- 查找我当前的点与我尝试访问的点之间的所有交点
- 如果不存在,请到下一个点
- 如果有,则绘制到此处,然后将下一个点设置到下一个点。 $ b
- 如果您不回到开头,那么转到2。
这是jsfiddle上的一个示例实现。注意:它没有优化。
Recently I've been thinking about how to transform a complex polygon into a non-complex polygon. How is this done?
This is the sort of thing I want to do:
I'm going to end up with JavaScript when I'm done, but any form of a solution is fine (language, algorithm, or just plain English).
解决方案
I would use the same heuristic that I would use when drawing the polygon by hand (which is probably not the most mathematically efficient way to caluclaute that polygon, but probably the easiest to understand/implement).
- Start at a point
- Find all the intersections between my current point and the point I'm trying to get to
- If none exist draw to the next point
- If one does, then draw to there, and then set the next point to the next point from there
- If you aren't back to the beginning then goto 2.
Here is an example implementation on jsfiddle. Note: it isn't optimized.
这篇关于我怎样才能简化一个复杂的多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文