Cylinder

version 1.2.0.0 (2.82 KB) by
This is the improved version of the previously submitted function 'cylinder2.m' .

Updated 15 May 2011

[X,Y,Z]=cylinder2(x,y,z,r,N,o)

Vectors x, y, z define the central line of cylindrical surface
and vector r defines the radius of cylindrical surface, and has
the same length as x, y, z.

N is the number of points around the circumference. The default value
is N = 100.

Matrix o defines ovality of the directrix (circle) of cylindrical
surface. Its elements take values between 0 and 1 and apply to the
primary and secondary axis of directrix. The defeault values are
o=ones(length(x),2).

Matrices X, Y, Z define the cylindrical surface, surf(X,Y,Z) displays
the cylindrical surface.

Example 1: Horn

f=linspace(0,4*pi,100);
x=cos(f); y=sin(f); z=f; r=-1/99*([1:100]-1)+1;
[X,Y,Z]=cylinder2(x,y,z,r);

Example 2: Pot

x=[0 0 1 1 .5 .5]; y=[0 0 3 3 1.5 1.5];
z=[0 0 2 2 1 1]; r=[0 1 1.5 1.2 1 0];
[X,Y,Z]=cylinder2(x,y,z,r,6); view([-150 25])

Example 3: Plumbing

x=[0 0 0 0 0 0 1 1 1 1 1 1]; y=[0 .2 .2 1 1 .5 .5 1 1 .2 .2 0];
z=[1 1 1 1 0 0 0 0 1 1 1 1]; r=[.2 .2 .1 .1 .1 .1 .1 .1 .1 .1 .2 .2];
o=[1 1 .5 .5 .5 1 1 .5 .5 .5 1 1; 1 1 1 1 1 .5 .5 1 1 1 1 1];
[X,Y,Z]=cylinder2(x,y,z,r,8,o);

Example 4: Triangle , closed central line

f=linspace(0,2*pi,4);
x=cos(f-pi/6); y=sin(f-pi/6); z=zeros(4,1); r=0.2*ones(4,1);
[X,Y,Z]=cylinder3(x,y,z,r); view([0 90])

Cite As

Avni Pllana (2022). Cylinder (https://www.mathworks.com/matlabcentral/fileexchange/31253-cylinder), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux