How do you use inpolygon?

6 vues (au cours des 30 derniers jours)
Jake
Jake le 12 Mai 2013
Commenté : Eddy Sanoli le 13 Mai 2020
I am trying to learn how to use this function. I have a photo of two buttons, and have acquired the bounding boxes for those buttons with their coordinates. The coordinates are saved in two matrices, one for x (Xcoordinates) and one for y (Ycoordinates).
Now I want the image to open and have the user click on one of the buttons using the inpolygon function. If the user clicks outside the bounding boxes, nothing is displayed, but if they click inside one of the buttons, information pertaining to that button is displayed.
I've defined xv to be Xcoordinates and yv to be Ycoordinates, for the inpolygon function, but I am not sure how the function works and how to implement for this thing I want to do.

Réponse acceptée

Image Analyst
Image Analyst le 12 Mai 2013
Wouldn't it just be
xVertices = [Xcoordinates(1), Xcoordinates(2), Xcoordinates(2), Xcoordinates(1)];
yVertices = [Ycoordinates(1), Ycoordinates(1), Ycoordinates(2), Ycoordinates(2)];
itsInside = inpolygon(x, y, xVertices, yVertices);
where x and y are what you got from ginput(1)? But it sounds like you already tried that, so am I missing something? Do you need a full blown demo?
  6 commentaires
Image Analyst
Image Analyst le 13 Mai 2013
Just call it 3 times, once with each set of vertices.
Eddy Sanoli
Eddy Sanoli le 13 Mai 2020
You can also separate the vertices of the different polygons with NaNs and the function will treat each sequence of vertices not separated with a NaN as an individual polygon

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Surfaces, Volumes, and Polygons 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!

Translated by