Drawing resizable (not intersecting) polygons

此生再无相见时 提交于 2020-01-01 06:06:08

问题


I have been searching everywhere but I could not find an answer. I need to have drawing resizable polygons with mouse interaction but I do not want irregular, overlapping or intersecting polygons in the end.

Here is a simple example of drawing resizable polygons http://www.wolfpil.de/polygon.html

You can easily create & resize polygons which is great. But I need an extra functionality to detect intersections and NOT allowing weird looking shapes/polygons. You can see the problem in this video: http://www.youtube.com/watch?v=zou2jcGM8zw

The only solution for that problem I found at http://www.wikimapia.org. They have added features to handle the problem. You can see it in this video: http://www.youtube.com/watch?v=K7-K0k2D-2A

I spent 3 days trying out to achieve something like this. I have gone through wikimapia's javascript code but it is way too complex for me to understand.

In sum, it does not have to look as fancy as as wikimapia's. I just need resizable polygons which do NOT intersect while resizing or adding new points to it. Can you give me any suggestions how to achieve that?

Thank in advance.


回答1:


Depending on how many points that you allow, a naive, simple O(N^2) line intersection algorithm suffices. Algorithmically this is not the best solution, but for starting out it's the most accessible for a beginner in computational geometry.

For starter, see Wikipedia article on line segment intersection. One of its links has an easy to understand explanation on how to compute the intersection point of two line segments.

Good luck!




回答2:


While this is not a complete answer, note that the example you supplied appears to be using the Geometry Controls from the GMaps Utility Library, which is an open source project hosted on Google Code.

You can check the full source code in the Google Code browser.



来源:https://stackoverflow.com/questions/2353409/drawing-resizable-not-intersecting-polygons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!