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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
daniel zayed
el 27 de Nov. de 2018
Comentada: Bruno Luong
el 27 de Nov. de 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 comentarios
Respuesta aceptada
Bruno Luong
el 27 de Nov. de 2018
Editada: Bruno Luong
el 27 de Nov. de 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 comentarios
Bruno Luong
el 27 de Nov. de 2018
If the vertexes are not properly ordered, then
all(ismember([1:length(x)],convhull(x,y)))
Más respuestas (1)
Image Analyst
el 27 de Nov. de 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 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!