Plot cube with certain length, width and height.
10 views (last 30 days)
Show older comments
I want to plot a beautiful 3D cube with certain length, width and height. Please help its urgent. I do not know MatLab programming.
This code gives me l, w and h.
disp('"Cybill Technologies"');
disp('By Asawira Emaan Khan');
disp('19I-2167');
disp(' ')
n = input('Press 1 to continue');
while(n == 1);
v = input('Enter volume.');
width = (9*v)/20;
w =nthroot(width, 3);
l = 2*w;
h = v/(2*(w*w));
cost = 20*(w*w) + (18*v)/w;
disp('Total cost: ');
disp(cost);
disp('Width: ');
disp(w);
disp('Length: ');
disp(l);
disp('Height: ');
disp(h);
%I need code there to plot a 3d cube for given dimensions.
n = input('Press 1 to continue or any other key to terminate');
end;
0 Comments
Answers (1)
Mann Baidi
on 29 Feb 2024
Hi,
As per my assumption you would like to plot a cuboid/cube with length,width and height as input.
For plotting a cube, you can add the following function in your code.
disp('"Cybill Technologies"');
disp('By Asawira Emaan Khan');
disp('19I-2167');
disp(' ')
n = input('Press 1 to continue');
while(n == 1)
v = input('Enter volume.');
width = (9*v)/20;
w =nthroot(width, 3);
l = 2*w;
h = v/(2*(w*w));
cost = 20*(w*w) + (18*v)/w;
disp('Total cost: ');
disp(cost);
disp('Width: ');
disp(w);
disp('Length: ');
disp(l);
disp('Height: ');
disp(h);
draw_cube(l,w,h)
%I need code there to plot a 3d cube for given dimensions.
n = input('Press 1 to continue or any other key to terminate');
end
function draw_cube(length, width, height)
% Define the vertices of the cube
vertices = [0 0 0;
length 0 0;
length width 0;
0 width 0;
0 0 height;
length 0 height;
length width height;
0 width height];
% Define the faces of the cube
faces = [1 2 6 5;
2 3 7 6;
3 4 8 7;
4 1 5 8;
1 2 3 4;
5 6 7 8];
% Draw the cube
patch('Vertices', vertices, 'Faces', faces, 'FaceColor', 'blue', 'FaceAlpha', 0.5);
% Set axis labels
xlabel('X');
ylabel('Y');
zlabel('Z');
% Set aspect ratio
axis equal;
% Set view
view(3);
end
Hope this will help with your query!
0 Comments
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!