File Exchange

image thumbnail

Cylinder

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

1 Download

Updated 15 May 2011

View Version History

View License

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

Comments and Ratings (4)

Sean Ellis

I built a model of a flexing tube actuator using Avni's software and enabled me to generate Node and Element Topology for subsequent Finite Element Analysis to work out flexing tube displacements. I modified the algorithm slightly and easily to give me tube ovality on minor and major axes in the same model.

joohyuk lee

It is what I've wanted. Thank you Pllana

joohyuk lee

Richard Crozier

Ok, I'm sure it's very good, but what does it actually do? I'm afraid I'm not familiar with cylinder2.m, as many people will not be. I'm guessing it draws a cylinder, but who knows?

MATLAB Release Compatibility
Created with R2010a
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!