Viewing a house in MATLAB

5 次查看(过去 30 天)
Hi, I would like to view the house given in the mat file.
When I issue:
load husdata.mat
patch(walls{1,1},walls{1,2},walls{1,3},'r')
set(gca,'projection','perspective')
view(3)
axis('off')
I get this
however, I think it should be a complete house, where one sees the roof. How can I view the whole thing and change the color of the roof into grey?
Thanks!

采纳的回答

Star Strider
Star Strider 2024-2-29
The walls and roof needed duplicates with some offsets to plot correctly. Other than that, the patch arguments are set up to be straightforward to plot (for which I am grateful, because 3D patch plots can sometimes be challenging). I coloured the walls differently to show their differences when viewed at different angles. Colour them as you prefer. In the second plot, I changed the roof colour to gray.
Try this —
load('husdata.mat')
% whos
R = roof;
W = walls;
figure
hold on
patch(W{1,1}, W{1,2}, W{1,3}, 'r')
patch(W{2,1}, W{2,2}, W{2,3}, 'g')
patch(W{1,1}, W{1,2}+9, W{1,3}, 'c')
patch(W{2,1}+6, W{2,2}, W{2,3}, 'm')
patch(R{1}, R{2}, R{3}, 'b')
patch(flip(R{1})+3.3, R{2}, R{3}, 'b')
hold off
xlabel('X')
ylabel('Y')
view(30,30)
title('House: Front View (Note: X & Y Coordinates)')
figure
hold on
patch(W{1,1}, W{1,2}, W{1,3}, 'r') % End Wall
patch(W{2,1}, W{2,2}, W{2,3}, 'g') % Side Wall
patch(W{1,1}, W{1,2}+9, W{1,3}, 'c') % End Wall
patch(W{2,1}+6, W{2,2}, W{2,3}, 'm') % Side Wall
patch(R{1}, R{2}, R{3}, [1 1 1]*0.5)
patch(flip(R{1})+3.3, R{2}, R{3}, [1 1 1]*0.5)
hold off
xlabel('X')
ylabel('Y')
view(210,30)
title('House: Rear View (Note: X & Y Coordinates)')
.
  2 个评论
Sergio
Sergio 2024-2-29
Thanks again @Star Strider, I will edit the colors further. Thanks!
Star Strider
Star Strider 2024-2-29
As always, my pleasure!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by