Adding a polyshape to a 3D plot (a la patch)
Show older comments
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

Accepted Answer
More Answers (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 Comments
KSSV
on 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
on 26 Mar 2019
KSSV
on 26 Mar 2019
I got this output:

Matt J
on 26 Mar 2019
KSSV
on 26 Mar 2019
What version you are on?
Matt J
on 26 Mar 2019
KSSV
on 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
on 26 Mar 2019
Matt J
on 26 Mar 2019
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
