Is there any way of finding a polygon that would contain all of a given list of points? without any intersections.
I'm hoping to use it in an app built on Google's Maps API v3. Any help/links would be much appreciated.
1–10 of 10 posts
Is there any way of finding a polygon that would contain all of a given list of points? without any intersections.
I'm hoping to use it in an app built on Google's Maps API v3. Any help/links would be much appreciated.
If you need to restrict yourself to following streets on the map, it might be a bit trickier...
If there's no restriction other than not wanting the lines to cross, then I'd find the centre of the polygon by taking the average of the list of points, then visiting those points in a clockwise direction. If you need to restrict yourself to following streets on the map, it might be a bit trickier...
Graphically:
X--X X-X X--X--X-X
| | / / | /
X X- | X X |
\ --X \ --X
X--/ X--/
Possible polygon Convex hull
based on the points of the points
marked X marked Xhttp://en.wikipedia.org/wiki/Convex_hull_algorithms
Alternatively, willvarfar's approach is faster for large n, but the polygon won't be as pretty.
If there's no restriction other than not wanting the lines to cross, then I'd find the centre of the polygon by taking the average of the list of points, then visiting those points in a clockwise direction. If you need to restrict yourself to following streets on the map, it might be a bit trickier...
streets dont matter, and thanks for the answer, are there any libraries for doing calulation like this, or would i have to write it manually?
You may mean "convex hull"; you should be able to find 2D and 3D algorithms easily (Wikipedia?). Graphically: X--X X-X X--X--X-X | | / / | / X X- | X X | \ --X \ --X X--/ X--/ Possible polygon Convex hull based on the points of the points marked X marked X
Finding the convex hull of a collection of points is a studied problem, so you can use an existing solution: http://en.wikipedia.org/wiki/Convex_hull_algorithms Alternatively, willvarfar's approach is faster for large n, but the polygon won't be as pretty.
Earlier quoted context omitted.
streets dont matter, and thanks for the answer, are there any libraries for doing calulation like this, or would i have to write it manually?
I've no idea, sorry.
http://opencv.willowgarage.com/documentation/cpp/structural_...
cv::convexHull