Finding intersection point for polygon with hole
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Torsten
le 30 Mar 2022
Modifié(e) : Torsten
le 30 Mar 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
le 30 Mar 2022
However linexlines2d function finds in an unexpected intersection point in x=0.1, y = 0.1 as seen in the figure.
Réponses (1)
Matt J
le 30 Mar 2022
Modifié(e) : Matt J
le 30 Mar 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 commentaires
Voir également
Catégories
En savoir plus sur Elementary Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
