How can we increase/decrease the number of triangles in a triangulation that is created from a polyshape object?

조회 수: 26 (최근 30일)
I wrote the following code:
C1 = polyshape(X1,Y1);
C2 = polyshape(X2,Y2);
C = subtract(C1,C2);
T = triangulate(C);
where X1, X2, Y1 & Y2 are column vectors of x- & y-coordinates of points that define the outer and inner boundaries of a region. The last command breaks the region C into triangles. My question is: How can we increase or decrease the numbr of triangles in the triangualtion or is it fixed?

답변 (3개)

Matt J
Matt J 2023년 5월 20일
편집: Matt J 2023년 5월 20일
To increase the number of triangles, you would have to add vertices along the edges, like in the following:
p1= polyshape([0,0; 1 0; 0 1]);
p2=polyshape([0,0,; 1 0; 0.5,0.5,;0,1],'Simplify',0);
doPlot(p1)
doPlot(p2)
function doPlot(p)
figure
plot(p,'FaceColor','g'); hold on
triplot(triangulation(p),'r'); hold off
axis equal
end
  댓글 수: 4
Image Analyst
Image Analyst 2023년 5월 22일
Add a very tiny bit of noise to the coordinates so they're no longer on a perfectly straight line.
Saad Mansoor
Saad Mansoor 2023년 5월 22일
Thank you Matt & Image Analyst for your valuable inputs. Yes, when I use 'Simplify',0) in the polyshape command it starts working. So I get the two figures shown below. The traingles span the whole width of the hexagonal ring. Any idea how to have smaller triangles?

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


Image Analyst
Image Analyst 2023년 5월 20일
To decrease the number of vertex points that describe a polygon while still somewhat resembling the original shape, see the algorithm in the attached paper.

Matt J
Matt J 2023년 5월 22일
편집: Matt J 2023년 5월 22일
Another way:
p1=nsidedpoly(6);
p2=p1.scale(0.5);
P=subtract(p1,p2);
P=subTri(P);
for i=1:3
P=splitTri(P);
end
plot(P); axis equal
function p=subTri(P)
%Sub-divide a scalar polyshape P into a vector of triangular sub-polyshapes
T=triangulation(P);
V=T.Points;
for i=height(T):-1:1
p(i)=polyshape(V(T(i,:),:));
end
p=p(:)';
end
function pnew=splitTri(p)
%Given a vector of triangular polyshapes, p, split each p(i) into smaller
%triangular polyshapes.
if isscalar(p)
V=interp1( p.Vertices([1,2,3,1],:) , 1:0.5:3.5);
pnew=subTri(polyshape(V,'Simplify',0));
else
C=arrayfun(@splitTri,p,'uni',0);
pnew=[C{:}];
end
end

카테고리

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