Algorithm to find figures using input points
I have just discussed with student and he told me him t开发者_开发问答ask, and I think it is interesting. The task. There are file with points like:
Point0: x=1; y=4;
Point1: x=199; y=45;
Point2: x=42; y=333;
Point3: x=444; y=444;
...
PointN: x=nnn; y=mmm;
You should find polygons and draw them. Each polygon present as internal I mean something like this:
---------
| ----- |
| | | |
| |----| |
| |
|--------|
And question what algorithm can you advice to use in this case? I understand this is from graph theory , but want opinion of other. Thanks.
Idea: Find the convex hull of all the points. For all the points that do not belong to the hull repeat the algorithm until no points left.
You could probably find a distance matrix for all the points and then do iterations like the following:
- Find the largest distance
- Draw rectangle for the two points which correspond to the found distance
- Remove these points from the list
- Repeat
精彩评论