![Plot a Cube centered at the origin - 2019 02 23.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205513/Plot%20a%20Cube%20centered%20at%20the%20origin%20-%202019%2002%2023.png)
Plot a Cube centered at the origin
117 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am trying to plot a cube with side lengths a, b and c centered at the origin but am having trouble to make it work. I have tried to make several 2D plots and plot them together but it doesn't really work. I hope someone here will be able to help me.
Thank You!
0 件のコメント
回答 (3 件)
Star Strider
2019 年 2 月 23 日
This should get you started:
a = -pi : pi/2 : pi; % Define Corners
ph = pi/4; % Define Angular Orientation (‘Phase’)
x = [cos(a+ph); cos(a+ph)]/cos(ph);
y = [sin(a+ph); sin(a+ph)]/sin(ph);
z = [-ones(size(a)); ones(size(a))];
figure
surf(x, y, z, 'FaceColor','g') % Plot Cube
hold on
patch(x', y', z', 'r') % Make Cube Appear Solid
hold off
axis([ -1 1 -1 1 -1 1]*1.5)
grid on
![Plot a Cube centered at the origin - 2019 02 23.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205513/Plot%20a%20Cube%20centered%20at%20the%20origin%20-%202019%2002%2023.png)
Experiment to get the result you want.
1 件のコメント
EMMANUEL VIRATEL
2020 年 3 月 29 日
Hello startrider
I'm emmanuel, a student of Toulouse (FRANCE) Pleased can you send me a script that draw the same cube as you, but that use a plot function from MATLAB not surf fonction
i will explain you later why,
Thanks a lot for your answer
Good luck with the coronavirus
Emmanuel
alejandro perez
2020 年 2 月 2 日
In the description of this video is the code of a cube which rotates, moves and grows up.
0 件のコメント
melvin mariadass
2020 年 7 月 29 日
Below is a solution to plot a cube using x,y,z coordinate using plot3d. Credit goes to Aggregate packing generator
b = 50; %inner square of the hollow beam for casting
l = 100;
x = [0 b b 0 ] %0 10 10 breadth-10 breadth-10 10];
y = [0 l];
z = [0 0 b b ] %0 10 10 breadth-10 breadth-10 10];
m = length(x);
xr=[x x(1)];
yr1=y(1)*ones(m+1,1);
zr=[z z(1)];
plot3(xr,yr1,zr,'k');
hold on
yr2=y(2)*ones(m+1,1);
plot3(xr,yr2,zr,'k');
hold on
for i=1:1:m
plot3([x(i) x(i)],y,[z(i) z(i)],'k');
end
hold on
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!