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
![](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 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!