Matlab point in polygon help needed
Code with C  Programming: Projects & Source Codes › Forums › MATLAB › Matlab point in polygon help needed
This topic contains 3 replies, has 1 voice, and was last updated by Adan 3 years, 3 months ago.

AuthorPosts

February 1, 2016 at 12:28 pm #9280
Basically when a user clicks any of the polygon I want a function that returns the polygon clicked as well as the area of the polygon.
Here is what I have so far, looking for suggestions to compute point in polygon and area. Thanks.
1234567891011121314151617181920212223242526272829clearclcCoord = [230 400; 270 420; 300 400;340 430;390 380; 230 300; 300 290;370 280;250 200;290 200 ;320 200 ;200 190 ;250 100 ;310 120; 410 110;390 180;];P = [1 6 7 3 2 1 NaN NaN;3 7 8 5 4 3 NaN NaN;6 9 10 7 6 NaN NaN NaN;7 10 11 8 7 NaN NaN NaN;6 12 13 14 10 9 6 NaN;8 11 10 14 15 16 8 NaN];patch('Faces',P,'Vertices',Coord,'FaceColor','w', 'Marker','o');%% Prompt user to click polygon%disp('Click any polygon')[s,t] = ginput(1);disp(sprintf('point(%8.6f ,%4.2f)',s,t))%% Function to determine polygon%%%Function to compute Area% 
February 1, 2016 at 12:28 pm #928112http://it.mathworks.com/help/matlab/ref/ginput.htmlhttp://it.mathworks.com/help/matlab/matlab_external/usingevents.html
Those came to my mind, I suggest you to stick with ginput.

February 1, 2016 at 12:28 pm #9282
The quick and dirt solution I think is through calculating the area and using a function that draw a polygon shaped button. It doesn’t seem too optimized. I’m looking through the documentation searching something clean. In the meantime you can “square” your polygon to obtain an approximate polygon and you can add a specific event when you click it. A sort of an invisible square that acts like a button.

February 1, 2016 at 12:29 pm #9283
I was thinking of writing a function that finds a point in polygon. The main challenge now is how this function will determine which polygon was clicked.
Because if I have:
Area = polyarea(polygon)
The polygon parameter has to be retrieved first from the click event before parsing into the area function. 
AuthorPosts
You must be logged in to reply to this topic.