How to make the 3d plot?
4 views (last 30 days)
Show older comments
vertex=[3 5 3 ; 7 5 5 ; 3 5 5 ; 3 6 5 ; 3 6 3];
face= [1 2 3 ; 2 3 4 ; 1 2 5 ; 2 4 5];
patch('Faces',face,'Vertices',vertex,'Facecolor',[0.8 0.8 1]);
view(3);
grid on
vertex=[3 5 3 ; 3 5 5 ; 3 6 5 ; 3 6 3];
face= [1 ; 2 ; 3 ; 4 ];
patch('Faces',face,'Vertices',vertex,'Facecolor',[0.8 0.8 1]);
view(3);
grid on
Hi guys i got confused about ploting 3-D pyramid.
Here ara the edge coordinates of the pyramid.
How can i plot it with all of its surfaces ?
0 Comments
Answers (1)
Walter Roberson
on 21 Mar 2020
vertex=[3 5 3 ; 7 5 5 ; 3 5 5 ; 3 6 5 ; 3 6 3];
face= [1 2 3 nan; 2 3 4 nan; 1 2 5 nan; 2 4 5 nan; 1 3 4 5];
patch('Faces',face,'Vertices',vertex,'Facecolor',[0.8 0.8 1]);
view(3);
grid on
4 Comments
Walter Roberson
on 21 Mar 2020
Total code:
vertex=[3 5 3 ; 7 5 5 ; 3 5 5 ; 3 6 5 ; 3 6 3];
face= [1 2 3 nan; 2 3 4 nan; 1 2 5 nan; 2 4 5 nan; 1 3 4 5];
patch('Faces',face,'Vertices',vertex,'Facecolor',[0.8 0.8 1]);
view(3);
grid on
The output:

This is correct output. You can use the plot tools to rotate it to see other faces.
The initial part of your original attempt was:

Notice the line from the bottom left corner. That is the internal edge of the corner "behind" the view, and it is visible because your original attempt did not draw the square face at the base of the pyramid. In the code I posted, you can tell that the square face has been drawn because that line is not visible.
If you want to see with more emphasis:
vertex=[3 5 3 ; 7 5 5 ; 3 5 5 ; 3 6 5 ; 3 6 3];
face= [1 2 3 nan; 2 3 4 nan; 1 2 5 nan; 2 4 5 nan; 1 3 4 5];
patch('Faces',face,'Vertices',vertex,'FaceVertexCData', hsv(size(vertex,1)));
shading interp
view(3);
grid on

See Also
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!