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 views (last 30 days)
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 .

Accepted Answer

Bruno Luong
Bruno Luong on 27 Nov 2018
Edited: Bruno Luong on 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)

More Answers (1)

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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!