How to plot closed polygon from set of random points with edges not intersecting?

I have set of random points in 2D plane, and have to make a closed polygon without any intersection between edges. There is a possibility that one or more polygons can be drawn. How do I get all those possible polygons along with their perimeter.

11 Comments

Sound to me like you want the convex hull of your set of points but I don't understand why you'd have several polygons. You illustration certainly doesn't explain that.
check this out at 1.11 and 1.16 sec, for the same points, 2 different polygons can be drawn. That's what i mean https://www.youtube.com/watch?v=SC5CX8drAtU
Yes..... Guillaume suggested convhull shall work.
Does convhull cover all the points? I want every point to be a vertex of polygon.
Mostly it should..if not you can also have a look on boundary.
No, convhull does not include all the points. Matlab does not have any built-in functions for that as far as I know. Your video suggests two different methods for achieving that. You'll have to implement them yourself or see if there's something on the file exchange.
I have just seen your video.....I think in your case boundary will work.
Boundary doesn't cover all the interior points
Did you try? Yes, you are right, it will not pick the interior points. Attach your points.....so that we can help you.
The points are random. If i give you certain points, it may work for those. What I need is a generic solution. Can anyone throw some light on polyshape?
polyshape does not have any function to do what you want, so it's not clear what light you need. As I said, there's nothing built into matlab to do that search, at least in base matlab. There's an example in the optimisation toolbox for something similar though.

Sign in to comment.

 Accepted Answer

How about this?
N = 100 ;
x = rand(1,N) ;
y = rand(1,N) ;
P = [x; y]; % coordinates / points
c = mean(P,2); % mean/ central point
d = P-c ; % vectors connecting the central point and the given points
th = atan2(d(2,:),d(1,:)); % angle above x axis
[th, idx] = sort(th); % sorting the angles
P = P(:,idx); % sorting the given points
P = [P P(:,1)]; % add the first at the end to close the polygon
plot( P(1,:), P(2,:), '.-r');

More Answers (0)

Categories

Tags

Asked:

on 11 May 2018

Commented:

on 14 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!