The "union" function for polyshapes performs an incorrect consolidation of adjacent polyshapes when presented as a vector
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matt J
am 7 Mai 2024
Bearbeitet: MathWorks Support Team
am 4 Jun. 2024
I have a polyshape vector "pv" consisting of 4 adjacent triangles:
load tstcase_pv
plot(pv)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1709131/7dd98e8da091f3ba6d73910bda69a2c1.png)
Why is it that when the polyshape vector elements are ordered one way, the "union" operation successfully consolidates them, whereas in the reverse order, it does not?
load tstcase_pv
pv1=pv([4,1,2,3]);
plot(union(pv1))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1709136/25fee7a43c12c899dce5e944d4773e56.png)
load tstcase_pv
pv1=pv([4,1,2,3]);
plot(union(pv1))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1709141/6eb871eb3f1a937ff9902b8c7c2e995f.png)
As an additional observation, I find that if the union is performed incrementally on two of the "pv(i)" at a time, using a for-loop, the problem does not manifest. Moreover, this is irrespective of the loop order.
load tstcase_pv
u=polyshape();
for i=randperm(4);
u=union(u,pv(i));
end
plot(u)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1709146/0a0d6d7b0aa68cc23e73c8264ee523bf.png)
1 Kommentar
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 8 Mai 2024
polyshapes contains oriented polygons. A polyshape with its vertices backwards is considered to be reverse direction.
This is important because multiple polyshapes together can describe "holes".
If you have two polyshapes with one insided the other, and the polyshapes are the same orientation, then the union of the two is the outer one. If the polyshapes are different orientation, then the union of the two is the area between the outer shape and the inner shape -- the inner shape will be a hole in the outer shape.
1 Kommentar
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!