Viewing a house in MATLAB

조회 수: 5 (최근 30일)
Sergio
Sergio 2024년 2월 29일
댓글: Star Strider 2024년 2월 29일
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