Plot a Cube centered at the origin
772 views (last 30 days)
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.
Star Strider on 23 Feb 2019
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))];
surf(x, y, z, 'FaceColor','g') % Plot Cube
patch(x', y', z', 'r') % Make Cube Appear Solid
axis([ -1 1 -1 1 -1 1]*1.5)
This plots the basic cube. UIse the rotate (link) function to change its orientation.
Experiment to get the result you want.
melvin mariadass on 29 Jul 2020
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);
plot3([x(i) x(i)],y,[z(i) z(i)],'k');