Plot structure in 3D coordinate

2 次查看(过去 30 天)
#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];

采纳的回答

Askic V
Askic V 2022-11-20
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 个评论
Milan
Milan 2022-11-21
Thanks, this worked out! What's is the meaning of view (45,15) which seems to have different effect?
Askic V
Askic V 2022-11-21
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by