Plot structure in 3D coordinate
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
#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
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 Commenti
Risposta accettata
Askic V
il 20 Nov 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 Commenti
Askic V
il 21 Nov 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!