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)
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 .

Respuesta aceptada

Bruno Luong
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
daniel zayed
daniel zayed el 27 de Nov. de 2018
Editada: daniel zayed el 27 de Nov. de 2018
thanks that was the pointx, how about to pick random points in polygon : ?
Bruno Luong
Bruno Luong el 27 de Nov. de 2018
If the vertexes are not properly ordered, then
all(ismember([1:length(x)],convhull(x,y)))

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
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.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by