intersection points between random polygon and a circle
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I have a random polygon (with known coordinates of the vertices) and a circle(with know center coordinates and center). I want to find the intersection points in between them. I have used linecirc function, but the problem is it also gives the intersection points which does not lie on the polygon. I have developed the following program, but sometimes it does not provide all the intersection points. Please help me to find out where I went wrong. Thanks
for i=1:length(V_x) %closed polygon with 7 vertices
V_x(8)=V_x(1);
V_y(8)=V_y(1);
m(i)=(V_y(i)-V_y(i+1))/(V_x(i)-V_x(i+1));
b(i)=-m(i)*V_x(i)+V_y(i);
[xout,yout] = linecirc(m(i),b(i),C_x,C_y,R);
crossX(i,1)=xout(1,1);
crossX(i,2)=xout(1,2);
crossY(i,1)=yout(1,1);
crossY(i,2)=yout(1,2);
DistCircleVertex(i)=distance(C_x,V_x(i),C_y,V_y(i));
EdgeLength(i)=distance(V_x(i),V_x(i+1),V_y(i),V_y(i+1));
DistPoint1Vertex1(i)=distance(V_x(i),crossX(i,1),V_y(i),crossY(i,1));
DistPoint1Vertex2(i)=distance(V_x(i+1),crossX(i,1),V_y(i+1),crossY(i,1));
DistPoint2Vertex1(i)=distance(V_x(i),crossX(i,2),V_y(i),crossY(i,2));
DistPoint2Vertex2(i)=distance(V_x(i+1),crossX(i,2),V_y(i+1),crossY(i,2));
%checking if intersection points lies on the polygon
if EdgeLength(i)==DistPoint1Vertex1(i)+DistPoint1Vertex2(i)& EdgeLength(i)==DistPoint2Vertex1(i)+DistPoint2Vertex2(i)
InpointX(i,1)=crossX(i,1);
InpointY(i,1)=crossY(i,1);
InpointX(i,2)=crossX(i,2);
InpointY(i,2)=crossY(i,2);
else if EdgeLength(i)==DistPoint1Vertex1(i)+DistPoint1Vertex2(i)
InpointX(i,1)=crossX(i,1);
InpointY(i,1)=crossY(i,1);
InpointX(i,2)=NaN;
InpointY(i,2)=NaN;
else if EdgeLength(i)==DistPoint2Vertex1(i)+DistPoint2Vertex2(i)
InpointX(i,1)=NaN;
InpointY(i,1)=NaN;
InpointX(i,2)=crossX(i,2);
InpointY(i,2)=crossY(i,2);
else
InpointX(i,1)=NaN;
InpointY(i,1)=NaN;
InpointX(i,2)=NaN;
InpointY(i,2)=NaN;
end
end
end
end
0 commentaires
Réponse acceptée
Matt J
le 9 Nov 2016
Modifié(e) : Matt J
le 9 Nov 2016
I have used linecirc function, but the problem is it also gives the intersection points which does not lie on the polygon.
Why not just discard the points that do not lie on the polygon? You can test this with inpolygon or with one of several File Exchange submissions, e.g.,
3 commentaires
Khouloud Eledlebi
le 3 Août 2017
Hello KalMandy, I am working on a project and I got stuck at how to find the intersection between polygon and circle. Can you please send me your final version of the code which you have adjusted earlier please. I would really appreciate your help very much
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Elementary Polygons dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!