Cylinder

Building cylinder without using cylinder-function

You are now following this Submission

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 (2026). Cylinder (https://www.mathworks.com/matlabcentral/fileexchange/94660-cylinder), MATLAB Central File Exchange. Retrieved .

Tags

Add Tags

Add the first tag.

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0