Adding a polyshape to a 3D plot (a la patch)
Afficher commentaires plus anciens
In the attached .mat file is a polyshape object which, when plotted in 2D, looks like an annulus,
Hpgon = plot(pgon); axis equal

Now, however, I would like to add this shape to the xy-plane of a 3D plot axis, filled with the same color. My first thought was to use patch(), as follows
vertices3D=pgon.Vertices;
vertices3D(:,3)=0;
faces3D=1:size(vertices3D,1);
patch('Vertices',vertices3D,'Faces',faces3D,'FaceColor',Hpgon.FaceColor);
camva auto
axis vis3d
This fails however, resulting in the unfilled plot below. I can see that patch() is having trouble interpreting this as a closed shape, but am not sure what the most efficient remedy would be. What is the best way to give patch() the same smarts as polyshape.plot()? Might there be an altogether different alternative to patch? It seems a shame that I cannot somehow do this directly with the polyshape object

Réponse acceptée
Plus de réponses (1)
load('example.mat')
Hpgon = plot(pgon); axis equal
vertices3D=pgon.Vertices;
vertices3D(:,3)=0;
faces3D=1:size(vertices3D,1);
vertices3D = [ NaN NaN NaN ;vertices3D ] ;
patch('Vertices',vertices3D,'Faces',faces3D,'FaceColor',Hpgon.FaceColor);
camva auto
axis vis3d

10 commentaires
KSSV
le 26 Mar 2019
It is working for second case also...the logic is the first and last points are joining...you should stop joining them...I have used NaN for this. Try:
vertices3D = [ NaN NaN NaN ;vertices3D;NaN NaN NaN ] ;
Matt J
le 26 Mar 2019
KSSV
le 26 Mar 2019
I got this output:

Matt J
le 26 Mar 2019
KSSV
le 26 Mar 2019
What version you are on?
Matt J
le 26 Mar 2019
KSSV
le 26 Mar 2019
I am on 2017b. You can save and share only vertices3D as a mat file.....it can be checked I guess.
Matt J
le 26 Mar 2019
Matt J
le 26 Mar 2019
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

