Bending the plane into a closed surface / cylinder

I am doing a math experiment in Matlab and the result should be a circle in the x, y plane. But sometimes the circle starts to spin. I am currently trying to bend the x, y plane into a cylinder (like in the following figure). At the moment I only have the x and y coordinates of the points.

I tried to convert them to polar coordinates and then use some "surf" commandos, but now nothing works

cylinder
(source: wtcoeselgem.be )

Edit: I used the plot3 command as suggested by Ander Biguri, resulting in the following figure.

cylinder2
(source: wtcoeselgem.be )

+3


source to share


2 answers


The following seems to do more or less of what you want

%// Data
xmin = -3;
xmax = 3; %// this piece will get folded into a cylinder
Rc = 5; %// cylinder radius
zmaxc = 5; %// cylinder max z
zminc = -5; %// cylinder min z

%// Spiral
t = linspace(0,1,1000);
r = 1+2*t;
theta = 2*pi*3*t;
x1 = r.*cos(theta);
y1 = r.*sin(theta); %// example spiral. Defined by x1, y1

%// Do the bending
z2 = y1;
phi = (x1-xmin)/(xmax-xmin)*2*pi;
x2 = Rc*cos(phi);
y2 = Rc*sin(phi);

%// Plot cylinder
[xc yc zc] = cylinder(Rc*ones(1,100),100);
zc = zminc + (zmaxc-zminc)*zc;
surf(xc,yc,zc)
shading flat
hold on

%// Plot bent spiral
plot3(x2,y2,z2, 'k.-');

      

Original spiral:

enter image description here



Two kinds of result:

enter image description here

enter image description here

+3


source


I will assume that you have a curve defined by coordinates x

and y

that you want to reset around the cylinder.

%% // Generate sample data
x = linspace(0,10*pi) ;
y2 = cos(x) ;
y1 = 10*cos(x/10) ;
y = y1+y2 ; y = y-min(y) ;
figure, plot(x,y,'-o') ;

      

This produces:
plot flat

Next, I define the base cylinder, nothing original:

%% // Basic cylinder (just for background)
[Xc,Yc,Zc] = cylinder(1,100);
Zc = Zc * max(y) ;
hs = surf(Xc,Yc,Zc) ;
set(hs,'FaceColor',[.8 .8 .8],'FaceAlpha',0.5,'EdgeColor','none') ;
hold on

      



And here's the interesting bit:

%% // Fold the points around the cylinder
Number_of_turn = 2 ;
xrange = [min(x),max(x)] ;
xspan = xrange(2)-xrange(1) ;
xc = x / xspan * 2*pi * Number_of_turn ;

Xp = cos(xc) ;
Zp = y ;
Yp = sin(xc) ;

hp = plot3(Xp,Yp,Zp,'-ok') ;

      

What render:
plot folded

In this example, I assumed you wanted to wrap your curve around the "2 turns" of the cylinder. This can be easily changed with a variable Number_of_turn

.

Note that you can also change the radius of the cylinder by multiplying the coordinates Xp

and Yp

by your radius.

+4


source







All Articles