Plot structure in 3D coordinate
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Milan
el 20 de Nov. de 2022
Comentada: Askic V
el 21 de Nov. de 2022
#I am trying to plot a structure as shown in figure below with a function, but am able to get just 2D plot, can you please help with this one
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200858/image.jpeg)
function[structplot] = plotstruct(coord, ends)
%input:
% ends:A Matrix specify the start node and end node;
% coord: the physical World Coordinate of all nodes (in mm)
structplot = figure;
xlabel('X (mm)');
ylabel('Y (mm)');
zlabel('Y (mm)');
axis off;
hold on
axis equal
% plot elements in form of lines
for i = 1:length(ends)
nodeA = ends(i, 1);
nodeB = ends(i, 2);
xLine = [coord(nodeA,1), coord(nodeB,1)];
yLine = [coord(nodeA,2), coord(nodeB,2)];
zLine = [coord(nodeA,3), coord(nodeB,3)];
plot(xLine, yLine,zLine, 'Color','black')
% label elements if requested
xAv = (xLine(1) + xLine(2))/2;
yAv = (yLine(1) + yLine(2))/2;
zAv = (zLine(1) + zLine(2))/2;
text(xAv, yAv,zAv, sprintf('%d', i))
end
% plot nodes
for i=1:length(coord)
plot(coord(i,1),coord(i,2) , 'r*');
text(coord(i,1),coord(i,2),sprintf('%d', i),'Color','blue');
end
end
# i have coord )coordination and ends -connectivityis the following form
coord = 1000 .*[-1 0 0;
1 0 0;
0 0 2.5;
0 1.5 2.5;
0 3 2.5;
-1 3 0;
1 3 0];
ends = [1 3;
2 3;
3 4;
4 5;
5 6;
5 7];
0 comentarios
Respuesta aceptada
Askic V
el 20 de Nov. de 2022
This slight modification is to get you going into right direction.
function[structplot] = plotstruct(coord, ends)
%input:
% ends:A Matrix specify the start node and end node;
% coord: the physical World Coordinate of all nodes (in mm)
structplot = figure;
xlabel('X (mm)');
ylabel('Y (mm)');
zlabel('Y (mm)');
axis off;
hold on;
axis equal
% plot elements in form of lines
for i = 1:length(ends)
nodeA = ends(i, 1);
nodeB = ends(i, 2);
xLine = [coord(nodeA,1), coord(nodeB,1)];
yLine = [coord(nodeA,2), coord(nodeB,2)];
zLine = [coord(nodeA,3), coord(nodeB,3)];
plot3(xLine, yLine,zLine, 'Color','black')
% label elements if requested
xAv = (xLine(1) + xLine(2))/2;
yAv = (yLine(1) + yLine(2))/2;
zAv = (zLine(1) + zLine(2))/2;
text(xAv, yAv,zAv, sprintf('%d', i))
end
% plot nodes
for i=1:length(coord)
plot3(coord(i,1),coord(i,2) ,coord(i,3),'r*');
text(coord(i,1),coord(i,2),sprintf('%d', i),'Color','blue');
end
view(45,15);
2 comentarios
Askic V
el 21 de Nov. de 2022
This is an extract from the documentation:
view(az,el) sets the azimuth and elevation angles of the camera's line of sight for the current axes.
check the documentation with
doc view
You can play with it and see how it works.
Más respuestas (0)
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!