How can I use one of the 3-D plot functions on the MATLAB to plot multiples 3-D polygons? Thank you

having a coordinate in this form: [53.366586, -6.234543] that represents a building for example. From tthis, how to plot the building in a 3D, in form of polygon assuming the height is 30m and the width and length is 5m.

 Respuesta aceptada

Try this:
l = 5; % Length
w = 5; % Width
h = 30; % Height
X = [-1 -1 1 1 -1; -1 -1 1 1 -1]*l;
Y = [-1 1 1 -1 -1; -1 1 1 -1 -1]*w;
Z = [ 1 1 1 1 1; 0 0 0 0 0]*h;
figure(1)
surf(X, Y, Z) % Plot Walls
hold on
patch(X(1,:), Y(1,:), Z(1,:), 'y') % Plot Flat Roof
hold off
grid on
axis equal
axis([-10 10 -10 10 0 40])
EDIT To plot multiple buildings:
figure(2)
surf(X, Y, Z) % Plot Walls - Building #1
hold on
patch(X(1,:), Y(1,:), Z(1,:), 'y') % Plot Flat Roof - Building #1
surf(X + ones(size(X))*15, Y + ones(size(Y))*20, Z) % Plot Walls - Building #2
patch(X(1,:) + 15, Y(1,:) + 20, Z(1,:), 'y') % Plot Flat Roof - Building #2
surf(X + ones(size(X))*35, Y + ones(size(Y))*25, Z) % Plot Walls - Building #3
patch(X(1,:) + 35, Y(1,:) + 25, Z(1,:), 'y') % Plot Flat Roof - Building #3
hold off
grid on
axis equal
axis([-10 50 -10 50 0 40])

4 comentarios

If you want to plot them at specific coordinates, such as [53.366586, -6.234543]:
C = [53.366586, -6.234543];
surf(X + ones(size(X))*C(1), Y + ones(size(Y))*C(2), Z) % Plot Walls - Building #4
patch(X(1,:) + C(1), Y(1,:) + C(2), Z(1,:), 'y') % Plot Flat Roof - Building #4
...and so for any others.
I do not have the Mapping Toolbox, so this is as much help as I can provide. Note that in my code, the coordinates will plot the centre of the building.
Experiment to get the result you want.
Is there any way to use this w=53.366586, l=-6.234543 instead?
As always, my pleasure!
‘Is there any way to use this w=53.366586, l=-6.234543 instead?’
Yes. The building can have any dimensions you want, and different buildings can have different dimensions, providing that the walls and roofs are squares or rectangles (as I have coded it). Note that ‘l’, and ‘w’ are the length and width of the building, respectively. You requested that the length and width be 5, and the height be 30, so I constructed them with those dimensions.

Iniciar sesión para comentar.

Más respuestas (1)

Oflive Mamena
Oflive Mamena el 5 de Mayo de 2018
Editada: Oflive Mamena el 5 de Mayo de 2018
This was what I did:
c=[53.382818, -1.488529]; %ext to hicks building
xx2=c(2);
distanceRequired=nm2deg(50*0.000539957);% Convert meters to nautical miles and then to degrees
[newlat newlon]=reckon('rh',c(1),c(2),distanceRequired,85); % straight line in the right hand side
xx1=newlon;
yy2=newlat;
distanceRequired=nm2deg(60*0.000539957)
[newlat newlon]=reckon('rh',c(1),c(2),distanceRequired,180); % straight line downwards
[newlat newlon]=reckon('rh',newlat,newlon,distanceRequired,85); % straight line in the right hand side
yy1=newlat;
% hold on
plot3 ( [xx1, xx2,xx2,xx1,xx1],[yy1, yy1,yy2,yy2,yy1],[30 30 30 30 30],'c','LineWidth',3);
hold on
plot3 ( [xx1, xx2,xx2,xx1,xx1],[yy1, yy1,yy2,yy2,yy1],[0 0 0 0 0],'c','LineWidth',3);
plot3 ( [xx2, xx2],[yy1 yy1],[30 0],'c','LineWidth',3);
plot3 ( [xx2, xx2],[yy2 yy2],[30 0],'c','LineWidth',3);
plot3 ( [xx1, xx1],[yy2 yy2],[30 0],'c','LineWidth',3);
plot3 ( [xx1, xx1],[yy1 yy1],[30 0],'c','LineWidth',3);

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 4 de Mayo de 2018

Comentada:

el 5 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by