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 Center および File ExchangeElementary Polygons についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by