Plot cube with certain length, width and height.
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Mann Baidi
2024-2-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!