필터 지우기
필터 지우기

Plot cube with certain length, width and height.

조회 수: 15 (최근 30일)
Asawira Emaan Khan
Asawira Emaan Khan 2020년 5월 20일
답변: Mann Baidi 2024년 2월 29일
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;

답변 (1개)

Mann Baidi
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!

카테고리

Help CenterFile Exchange에서 Surfaces, Volumes, and Polygons에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by