how can i valid if the polygon i have received , X=[x1,x2,x3,x4] Y =[y1,y2,y3,y4] has no internal angle bigger than 180
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
daniel zayed
le 27 Nov 2018
Commenté : Bruno Luong
le 27 Nov 2018
how can i valid if the polygon i have received , X=[x1,x2,x3,x4] Y =[y1,y2,y3,y4] has no internal angle bigger than 180 ;
i am given X and Y and ineed to check that condition ?
can anybody help me , thx .
i have another question , can i let matlab pick me aroandom coordinates (x,y) such that they are inside or on the polygon ihave recieved .
0 commentaires
Réponse acceptée
Bruno Luong
le 27 Nov 2018
Modifié(e) : Bruno Luong
le 27 Nov 2018
That simply means the polygonal is convex. To check it
K = convhull(x,y);
isequal([1:length(x) 1]',K) || isequal([1 length(x):-1:1]',K)
2 commentaires
Bruno Luong
le 27 Nov 2018
If the vertexes are not properly ordered, then
all(ismember([1:length(x)],convhull(x,y)))
Plus de réponses (1)
Image Analyst
le 27 Nov 2018
I was going to suggest the convex hull like Bruno. I think you might also need to make sure the polygon doesn't cross, like a figure 8.
For the points in a polygon, just get a random point and use inpolygon() to check if it's inside the polygon or not. If it is, keep it, if it's not, keep trying until you have the required number of points inside. Something like (untested)
numRequired = 1000;
rx = rand(1, numRequired*4); % Make sure there are enough to handle rejects.
ry = rand(1, numRequired*4); % Make sure there are enough to handle rejects.
keeperIndexes = false(1, numRequired)*4; % Flag to say if it's inside the x,y polygon.
for k = 1 : length(x)
if inpolygon(rx, ry, x, y)
keeperIndexes(k) = true;
% Break if we've found enough.
if sum(keeperIndexes) >= numRequired
break;
end
end
end
% Extract the keepers - those inside the polygon.
keeperX = rx(keeperIndexes);
keeperY = ry(keeperIndexes);
Make sure x and y are ordered. I also think the polygon needs to be closed, but I'm not sure.
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!