Finding intersection point for polygon with hole

조회 수: 3 (최근 30일)
Kayra Dernek
Kayra Dernek 2022년 3월 30일
댓글: Matt J 2022년 3월 30일
I am trying to find intersection points of polygons with holes and lines. However linexlines2d function finds in an unexpected intersection point in x=0.1, y = 0.1 as seen in the figure. Is there a way to prevent this. By the way I am trying to find intersection points so that I can discretisize the boundry with additional nodes with linspace function. Then I will use delauneyTriangulation to mesh the surface. So my main goal is to be able to mesh any polygon. I would really appreciate any other recomendation to achive this result.
Thanks
clc
clear
clf
polyOut=polyshape([0 0; 1 0; 0 1]); %Create triangular polyshape with hole
polyIn=polyOut.scale(0.5,[1/3,1/3]);
poly=polyOut.subtract(polyIn);
plot(poly)
hold on
for i=0:0.1:1
[x1,y1,x2,y2]=deal(-1,i,2,i); %line from (0,0) to (1,1)
out=linexlines2D(poly,[x1,y1],[x2,y2]);
%Visualize
col=[0.6400 0.0800 0.1800];
plot([x1,x2],[y1,y2],'--','Color',col);
plot(out(1,:),out(2,:),'o','MarkerFaceColor','r');
end
  댓글 수: 2
Torsten
Torsten 2022년 3월 30일
편집: Torsten 2022년 3월 30일
If the aim is to create a boundary mesh, why don't you use the parametric form of the boundary to create points on it ?
E.g. a circle is given by (R*cos(t),R*sin(t)) for 0<=t<2*pi.
Now just use
R = 1;
f = @(t) [R*cos(t);R*sin(t)];
t = linspace(0,2*pi,10);
S = f(t);
plot (S(1,:),S(2,:))
Matt J
Matt J 2022년 3월 30일
However linexlines2d function finds in an unexpected intersection point in x=0.1, y = 0.1 as seen in the figure.
A debugged version of the File Exchange file linexlines2D has now been uploaded.

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

답변 (1개)

Matt J
Matt J 2022년 3월 30일
편집: Matt J 2022년 3월 30일
By the way I am trying to find intersection points so that I can discretisize the boundry with additional nodes with linspace function
Here's an easier way to add more edge samples:
polyOut=polyshape([0 0; 1 0; 0 1]); %Create triangular polyshape with hole
polyIn=polyOut.scale(0.5,[1/3,1/3]);
V=[morepoints(polyOut,15);morepoints(polyIn,10)];
plot(V(:,1),V(:,2),'or','MarkerFace','r'); axis equal; axis padded
hold on; plot(subtract(polyOut,polyIn),'FaceColor','b') ; hold off
function V=morepoints(poly,N)
%Create a list of points along polyshape edges, N per side.
t=linspace(0,1,N)'; t(end)=[];
V=poly.Vertices;
V=kron(V,t)+kron(V([2:end,1],:), 1-t);
end

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by