image thumbnail

Cylinder

version 1.0.0 (1.45 KB) by Artem Sulim
Building cylinder without using cylinder-function

1 Download

Updated 22 Jun 2021

View License

clear all
close all
clc
%--------------------------------------------------------------------------
%***************************** CYLINDER ***********************************
%--------------------------------------------------------------------------
A = 0; % alpha mod: 1 - on / 0 - off.
r = linspace(1,3,20); % radius of cylinder;
u = linspace(-pi,pi,50); % u parameter;
v = 0:7; % v parameter;
%------------------------------------------
%**** lateral surface of the cylinder ****|
%------------------------------------------
for i = 1:length(r)
[U,V] = meshgrid(u,v);
x = r(i).*cos(U);
y = r(i).*sin(U);
z = V;
if A == 1
s = surf(x,y,z)
hold on
alpha(s,0.3)
else
s = surf(x,y,z)
hold on
end
end
%------------------------------------------
%******* top and bottom end-cup **********|
%------------------------------------------
theta = linspace(min(u),max(u),length(u));
r = linspace(min(r),max(3),length(r));
[THETA,R]=meshgrid(theta,r);
for i = 0:max(v)
z = zeros(size(R))+i;
[X,Y,Z]=pol2cart(THETA,R,z);
if A == 1
s = surf(X,Y,Z)
alpha(s,0.3)
else
s = surf(X,Y,Z)
end
end
zlim([min(v)-2 max(v)+2])
colormap('winter')
xlabel('X')
ylabel('Y')
zlabel('Z')

Cite As

Artem Sulim (2021). Cylinder (https://www.mathworks.com/matlabcentral/fileexchange/94660-cylinder), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!