um how do you plot rectangles in different parts of a bigger rectangle kinda like a room using coordinates of the bottom left hand cornwer

3 次查看(过去 30 天)
numberFloors=inputdlg({'Please Enter The Number Of Floors Required:'});
numberFloors=str2double(numberFloors{1});
if numberFloors<=0
disp('Number of floors must be at least 1');
return
else
disp('Thanks');
end
floorLength=zeros(1,numberFloors);
floorWidth=zeros(1,numberFloors);
floorHeight=zeros(1,numberFloors);
numberRooms=zeros(1,numberFloors);
mainlooptotal=1;
while mainlooptotal<=numberFloors
for i=1:1:numberFloors
floorLength(i)=input(['Please enter floor ',num2str(mainlooptotal),' length: ']);
floorWidth(i)=input(['Please enter floor ',num2str(mainlooptotal),' width: ']);
floorHeight(i)=input(['Please enter floor ',num2str(mainlooptotal),' height: ']);
numberRooms(i)=input(['Please enter the number of rooms on floor ',num2str(mainlooptotal),': ']);
if floorLength(i)<=0 || floorWidth(i)<=0 || floorHeight(i)<=0 || numberRooms(i)<=0
disp('Floor dimensions and number of rooms must be greater than 0');
return
else
mainlooptotal=mainlooptotal+1;
end
roomLength=zeros(1,(numberRooms(i)));
roomWidth=zeros(1,(numberRooms(i)));
roomlooptotal=1;
while roomlooptotal<=numberRooms
for j=1:1:numberRooms
typeofroom =('type of room');
numberType=inputdlg({'Please enter the type of room(residential, office, education, toilet or storage)'});
roomLength(j)=input(['Please enter room ',num2str(roomlooptotal),' length: ']);
roomWidth(j)=input(['Please enter room ',num2str(roomlooptotal),' width: ']);
roomHeight(j)=input(['Please enter room ',num2str(roomlooptotal),' height: ']);
if roomLength(j)<=0 || roomWidth(j)<=0 || roomHeight(j)<=0
disp('Room dimensions must be greater than 0');
return
else
roomYcoordinates= input('y coordinate of room:');
roomxcoordinates= input('x coordinate of room:');
roomlooptotal=roomlooptotal+1;
end
end
end
end
end
choice = questdlg('What type of environment would your building be in', 'Question','Urban', 'Sub-urban','Urban');
if isequal(choice,'Urban')
disp('Urban');
else
disp('Something else');
end
save('lolhyf')
load('lolhyf.mat');

回答(1 个)

Arun
Arun 2023-10-13
Hey Oluwaseun Adetunji,
I understand that you want to create rooms within a house, for which you want to plot cuboids inside a cuboid where cuboids will represent rooms and intent to use the left-hand corner of the house as coordinate axis.
To accomplish this, you can make use of the function from the MathWorks File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube
Plotcube displays a 3D-cube in the current axes. Parameters used by the function are:
  1. Edes (3-element vector for edge dimensions).
  2. Origin (defines the start point in 3D space).
  3. Alpa (transparency of the cube).
  4. Color (3-element vector for faces color).
I am sharing a sample code and output for more clarity:
plotcube([5 5 5],[ 2 2 2],.8,[1 0 0]); %bigger cuboid
plotcube([2 2 2],[2 2 2],.8,[0 1 0]); %smaller inner cuboid
plotcube([2.5 2.5 2],[2 2 4],.8,[0 1 0]);%smaller inner cuboid
plotcube([1 1 1],[5 2 2],.8,[0 0 1]);%smaller inner cuboid
I hope the given information helps you with your implementation.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by