使用java/android中给定的点绘制凸包
我给出了一些 2D 点,我想使用这些点绘制一个多边形。该多边形必须经过所有给定的点,这意味着不存在位于多边形内部或外部的点。
例如:如果我有如下点:(0,0)、(1,1)、(-1,-1)、(-1,1) 和 (1,-1) 并且如果我想绘制一个多边形使用这些,那么我的点数组应该按以下方式排序:
(1,1) -> (1,-1)-> (-1,-1)→ (-1,1)-> (0,0)-> (1,1)或
(1,1)→ (0,0)-> (-1,1)-> (-1,-1)→ (1,-1)→ (1,1)
但不可能是:
(1,1) -> (0,0)-> (-1,-1)→ (-1,1)-> (-1,1)-> (1,-1)→ (1,1)
为了绘制多边形,我使用 drawLine 函数,从一个点到另一个点,最后从最后一个点到第一个点绘制线条。
有没有可用的算法或代码?
谢谢!!
I have some 2D points given and i want to draw a polygon using those points. This polygon must pass through all the given points means there is no such point which is inside or outside the polygon.
For example: if i have points like: (0,0), (1,1), (-1,-1),(-1,1) and (1,-1) and if i want to draw a polygon using those then my points array should be sorted in following manner:
(1,1) -> (1,-1) -> (-1,-1) -> (-1,1) -> (0,0) -> (1,1) OR
(1,1) -> (0,0) -> (-1,1) -> (-1,-1) -> (1,-1) -> (1,1)
but it cant be:
(1,1) -> (0,0) -> (-1,-1) -> (-1,1) -> (-1,1) -> (1,-1) -> (1,1)
For drawing the polygon, i am using drawLine function and drawing lines from one to another point and finally from last to first point.
Is there any algorithm or code available for this?
thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在谷歌中快速搜索:凸包算法,这是一个Java 实现。
编辑:重新阅读您的问题并意识到这不是您想要的。标题“凸包”可能会产生误导......
A quick search in google : convex hull algorithms, and here is a Java implementation.
EDIT : re-read your question and realised it is not what you wanted. The title "Convex Hull" can be misleading...
我认为你的问题并不像看起来那么微不足道。恕我直言,它是旅行推销员问题的特殊形式,但没有相交的路径。
I think your problem is not as trivial as it seems. IMHO its a special form of the travelling salesman problem, but without intersecting paths.