Draw a convex hull using the given points in java/android

与世无争的帅哥 提交于 2019-12-11 08:41:22

问题


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!!


回答1:


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...




回答2:


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.



来源:https://stackoverflow.com/questions/5646924/draw-a-convex-hull-using-the-given-points-in-java-android

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