Filter löschen
Filter löschen

Viewing a house in MATLAB

3 Ansichten (letzte 30 Tage)
Sergio
Sergio am 29 Feb. 2024
Kommentiert: Star Strider am 29 Feb. 2024
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!

Akzeptierte Antwort

Star Strider
Star Strider am 29 Feb. 2024
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 Kommentare
Sergio
Sergio am 29 Feb. 2024
Thanks again @Star Strider, I will edit the colors further. Thanks!
Star Strider
Star Strider am 29 Feb. 2024
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by