plot graph with cylinder

3 ビュー (過去 30 日間)
Gaetano Pavone
Gaetano Pavone 2020 年 1 月 28 日
回答済み: ag 2025 年 1 月 30 日
Is it possible to plot a 3d graph by using a cylinders (or a tubes) instead of the default straight lines in Matlab?

回答 (1 件)

ag
ag 2025 年 1 月 30 日
Yes it is possible to plot 3d graph by using cylinders. To do so you may utilize the "cylinder" MATLAB function as demonstrated in the below code:
% Define the path of the 3D line
x = [1, 2, 3, 4, 5];
y = [1, 2, 1, 2, 1];
z = [1, 2, 3, 4, 5];
% Define the radius of the tube
radius = 0.1;
% Number of segments
n = numel(x);
% Plot each segment as a cylinder
hold on;
for i = 1:n-1
[X, Y, Z] = cylinder(radius, 20);
Z = Z * norm([x(i+1)-x(i), y(i+1)-y(i), z(i+1)-z(i)]);
surf(X + x(i), Y + y(i), Z + z(i), 'EdgeColor', 'none');
end
hold off;
% Adjust the view
view(3);
axis equal;
For more details, please refer to the following MathWorks documentation: https://www.mathworks.com/help/matlab/ref/cylinder.html
Hope this helps!

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by