필터 지우기
필터 지우기

intersection points between random polygon and a circle

조회 수: 1 (최근 30일)
KalMandy
KalMandy 2016년 11월 9일
댓글: Khouloud Eledlebi 2017년 8월 3일
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

채택된 답변

Matt J
Matt J 2016년 11월 9일
편집: Matt J 2016년 11월 9일
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
KalMandy
KalMandy 2016년 11월 9일
Hi Matt, I figured out the way to use inpolygon for my case. Thank you very much!
Khouloud Eledlebi
Khouloud Eledlebi 2017년 8월 3일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by