フィルターのクリア

Plot structure in 3D coordinate

2 ビュー (過去 30 日間)
Milan
Milan 2022 年 11 月 20 日
コメント済み: Askic V 2022 年 11 月 21 日
#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 Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by