ABC
ABC

Reputation: 125

Bending a plane into a closed surface/cylinder

I'm doing a mathematical experiment in Matlab and the result should be a circle in the x,y-plane. But sometimes, the circle starts spiraling. I'm now trying to bend the x,y-plane into a cylinder (as in the following picture). At the moment I only have the x and y coordinates of the points.

I've tried converting them into polar coordinates and then use some 'surf' commando's, but nothing works right now

cylinder
(source: wtcoeselgem.be)

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

cylinder2
(source: wtcoeselgem.be)

Upvotes: 3

Views: 1371

Answers (2)

Luis Mendo
Luis Mendo

Reputation: 112689

The following seems to do more or less 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 views of the result:

enter image description here

enter image description here

Upvotes: 3

Hoki
Hoki

Reputation: 11802

I will consider that you have a curve defined by x and y coordinates which you want to fold around a 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 a basic 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 comes 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') ;

Which render:
plot folded

For this example I assumed you wanted to wrap your curve around "2 turns" of the cylinder. This is easily changed with the Number_of_turn variable.

Note that you can also change the radius of the cylinder by multiplying the Xp and Yp coordinates by your radius.

Upvotes: 4

Related Questions