I am attempting to graph a Triangular Prism
Show older comments
I'm new to matLab and I am trying to graph a triangular prism. I am currently attempting to use the patch function. Is there any easier way to do this or do I just need to continue to play with current method I am using until it looks correct?
x = [0 0 0 8 8 0 8 ]
y = [0 6 3 3 0 0 6 ]
z = [0 0 4 4 0 0 0 ]
patch(x,y,z, 'r')
Answers (1)
John BG
on 16 Feb 2016
the way you are defining the vertices of the prism is not clear:
write the vertices coordinates vertically and introduce them horizontally, for instance the most basic prism would be, with command fill3:
X = [0 0 1 0]
Y = [0 1 0 0]
Z = [1 0 0 0]
fill3(X,Y,Z,[1 1 1 1])
the 4th input is the vector with colours for prism faces.
Now with patch:
X = [0 0 1 0]
Y = [0 1 0 0]
Z = [1 0 0 0]
patch(X,Y,Z)
There's still an open face.
To set properties of all faces use patch.
The next prism would be a cube, have a look to MATLAB help: POLYGONS > examples and how to:
You can also introduce all vertices horizontally, but you also have to define all the faces
vert = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1];
fac = [1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;1 2 3 4;5 6 7 8];
patch('Vertices',vert,'Faces',fac,'FaceVertexCData',hsv(6),'FaceColor','flat')
view(3)
axis vis3d
If you find this answer of any help solving your question, please click on the thumbs-up vote link above, thanks in advance
John
Categories
Find more on Bar 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!