how to plot a prism
38 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
reza hamzeh
el 8 de Nov. de 2019
Comentada: Star Strider
el 8 de Nov. de 2019
hi. i tried to plot a prism with a n-sides base. i only could plot the 2 bases (for n =8). now i have no idea how to plot the faces. plz help me
n=8;
A=ones(n+1);
z1=2;h=3;
z=A(:,1)*z1;
zz=z+h;
t = 0:2*pi/n:2*pi;
x=cos(t);
y=sin(t);
plot3(x,y,z)
hold on
plot3(x,y,zz)
![r.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247440/r.jpeg)
0 comentarios
Respuesta aceptada
Star Strider
el 8 de Nov. de 2019
Use surf instead of plot3 if you want solid-appearing sides.
Try this:
figure
surf([x;x].', [y;y].', [z,zz], 'FaceColor','g')
grid on
% axis equal
% shading('interp')
The axis and shading calls are optional. Note that the surf arguments are two-column martices.
2 comentarios
Star Strider
el 8 de Nov. de 2019
My pleasure!
The [x;x].', [y;y].', and [z,zz] concatenate the vectors (and transpose them if necessary) to create equal sized matrices for surf to use. The MATLAB surface plotting functions use matrices, not vectors, so in this instance it is necessary to create matrices in order for the surf plot to be correct.
figure
surf([x;x].', [y;y].', [z,zz], 'FaceColor','g')
hold on
patch([x;x].', [y;y].', [z,zz], 'r') % Color Both Ends Red
hold off
grid on
axis equal
figure
surf([x;x].', [y;y].', [z,zz], 'FaceColor','g')
hold on
patch([x;x].', [y;y].', [zz,zz], 'r') % Color One End Red
patch([x;x].', [y;y].', [z,z], 'b') % Color Other End Blue
hold off
grid on
axis equal
Rotate the figures in the GUI to see the end colours. ![how to plot a prism - 2019 11 08.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247456/how%20to%20plot%20a%20prism%20-%202019%2011%2008.png)
![how to plot a prism - 2019 11 08.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247456/how%20to%20plot%20a%20prism%20-%202019%2011%2008.png)
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!