Is there a built-in function that determines whether X/Y coordinates give valid polygon?
2 次查看(过去 30 天)
显示 更早的评论
If I have a vector of X-coordinates and a vector of Y-coordinates, is there a function that determines whether a valid polygon is created based on the order of the X/Y coords (i.e., lines connecting points do not criss-cross). I envision it would work something like this:
Valid polygon would be:
>> xy = [0,0; 1,0; 1,1; 0,1; 0,0];
>> ispoly(xy)
ans =
1
Not a valid polygon:
>> xy = [0,0; 1,0; 0,1; 1,1; 0,0];
>> ispoly(xy)
ans =
0
If nothing exists... no worries I'll sit down and work out my own function.
0 个评论
回答(3 个)
Image Analyst
2012-7-19
Elige, you need to search for "detect self-intersecting polygon". You can add MATLAB if you want to the search terms. You'll get lots of hits, including this one from Buno Luong which has MATLAB code:
Star Strider
2012-7-18
I'm not certain this does what you want, but experimenting with ‘convhull’ might provide a solution:
xy1 = [0,0; 1,0; 1,1; 0,1; 0,0];
xy2 = [0,0; 1,0; 0,1; 1,1; 0,0];
[K1,V1] = convhull(xy1(:,1), xy1(:,2));
[K2,V2] = convhull(xy2(:,1), xy2(:,2));
dK1 = diff(K1);
dK2 = diff(K2);
The list in ‘K1’ is in order, the list in ‘K2’ is not, so ‘dK1’ has only one (-)ve element while ‘dK2’ has two. You'll likely have to write your own ‘ispoly’ function, but ‘convhull’ may make that easier.
2 个评论
Image Analyst
2012-7-19
I don't see how convhull() would help. It's not hard to think of several examples where the convex hull of an ordered set of points would have no knowledge of whether interior points were looping/crossing each other or not.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!