Finding intersection point for polygon with hole
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Torsten
am 30 Mär. 2022
Bearbeitet: Torsten
am 30 Mär. 2022
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
am 30 Mär. 2022
However linexlines2d function finds in an unexpected intersection point in x=0.1, y = 0.1 as seen in the figure.
Antworten (1)
Matt J
am 30 Mär. 2022
Bearbeitet: Matt J
am 30 Mär. 2022
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Elementary Polygons 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!
