How to say the third selected point lies within the created geometry or not?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ramesh Bala
am 24 Jul. 2018
Kommentiert: Ramesh Bala
am 26 Jul. 2018
close all
clc
base_x = [0 50 50 20 0 0]
base_y = [0 0 10 10 10 0 ]
roof_x = [ 0 0 20 20 30 30]
roof_y =[ 10 50 10 50 50 10]
figure
plot(base_x, base_y,'-')
hold on
plot(roof_x, roof_y,'-')
axis([0 50 0 50])
grid on
[X,Y]=meshgrid(1:11);
[x] = ginput(2);
[x] = round(x);
fprintf ('the a1 coordinate value is %d,\n' , x(1,1));
fprintf ('the b1 coordinate value is %d ,\n' , x(1,2));
fprintf ('the a2 coordinate value is %d,\n' , x(2,1));
fprintf ('the b2 coordinate value is %d ,\n' , x(2,2));
How to say the third selected points a1,b1 a2,b2 lies within the created geometry ( base,roof) or not?
4 Kommentare
Walter Roberson
am 25 Jul. 2018
Question was continued at https://www.mathworks.com/matlabcentral/answers/412069-determining-point-is-within-polygon-or-outside
Adam Danz
am 25 Jul. 2018
Kaleesh, I'm continuing your other thread (link above) here because this topic seems to be more relevant to the problems you're having.
Akzeptierte Antwort
Adam Danz
am 24 Jul. 2018
Bearbeitet: Adam Danz
am 25 Jul. 2018
If I understand your question correctly, you're trying to determine if a coordinate (x,y) lies within a polygon.
First try matlab's inpolygon().
Another way to achieve that is by "ray casting". The idea is to draw a line from the (x,y) coordinate and extend it rightward until it passes all of the possible polygon edges. Then count the number of times that ray intersects with an edge of the polygon. If that number is non-zero and odd, then the coordinate (x,y) is within the polygon.
5 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!