3D Mesh Generation in Cylindrical Coordinates
clc
clear
M=20;
N=2*M;
L=4;
r=1;
r1=1.5;
r2=2;
T=-1;
TT=1;
for j=1:L;
thet(1)=0; T=T+TT;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x(i,j)=r*cos(theta(i));
y(i,j)=r*sin(theta(i));
z(i,j)=T; end thet(1)=0;
for i=1:N+1; dt=360/N;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x1(i,j)=r1*cos(theta(i));
y1(i,j)=r1*sin(theta(i));
z1(i,j)=T+0.5*TT;
end thet(1)=0;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x2(i,j)=r2*cos(theta(i));
y2(i,j)=r2*sin(theta(i));
z2(i,j)=T;
end
end
plot(x,y,'-',x2,y2,'-');
hold on
ff=0;
for j=1:L-1;
for i=1:N;
ff=ff+1;
a(i)=rem(ff,2);
if (a(i)==1)
plot3(x1(i,j),y1(i,j),z1(:,j),'-*r');
hold on
end
end
end
grid on
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
title('Cylindrical Mesh')
for j=1:L;
for i=1:M
v1=[x(i+1,j),x(i,j)];
v2=[y(i+1,j),y(i,j)];
v3=[z(i+1,j),z(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L-1;
for i=1:N
v1=[x1(i+1,j),x1(i,j)];
v2=[y1(i+1,j),y1(i,j)];
v3=[z1(i+1,j),z1(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L;
for i=1:M
v1=[x2(i+1,j),x2(i,j)];
v2=[y2(i+1,j),y2(i,j)];
v3=[z2(i+1,j),z2(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L;
for i=1:M
v1=[x2(i,j),x(i,j)];
v2=[y2(i,j),y(i,j)];
v3=[z2(i,j),z(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L-1;
for i=1:M
v1=[x(i,j),x(i,j)];
v2=[y(i,j),y(i,j)];
v3=[z(i,j+1),z(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L-1;
for i=1:M
v1=[x2(i,j),x2(i,j)];
v2=[y2(i,j),y2(i,j)];
v3=[z2(i,j+1),z2(i,j)];
f=line(v1,v2,v3);
end
end
clear
M=20;
N=2*M;
L=4;
r=1;
r1=1.5;
r2=2;
T=-1;
TT=1;
for j=1:L;
thet(1)=0; T=T+TT;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x(i,j)=r*cos(theta(i));
y(i,j)=r*sin(theta(i));
z(i,j)=T; end thet(1)=0;
for i=1:N+1; dt=360/N;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x1(i,j)=r1*cos(theta(i));
y1(i,j)=r1*sin(theta(i));
z1(i,j)=T+0.5*TT;
end thet(1)=0;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x2(i,j)=r2*cos(theta(i));
y2(i,j)=r2*sin(theta(i));
z2(i,j)=T;
end
end
plot(x,y,'-',x2,y2,'-');
hold on
ff=0;
for j=1:L-1;
for i=1:N;
ff=ff+1;
a(i)=rem(ff,2);
if (a(i)==1)
plot3(x1(i,j),y1(i,j),z1(:,j),'-*r');
hold on
end
end
end
grid on
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
title('Cylindrical Mesh')
for j=1:L;
for i=1:M
v1=[x(i+1,j),x(i,j)];
v2=[y(i+1,j),y(i,j)];
v3=[z(i+1,j),z(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L-1;
for i=1:N
v1=[x1(i+1,j),x1(i,j)];
v2=[y1(i+1,j),y1(i,j)];
v3=[z1(i+1,j),z1(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L;
for i=1:M
v1=[x2(i+1,j),x2(i,j)];
v2=[y2(i+1,j),y2(i,j)];
v3=[z2(i+1,j),z2(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L;
for i=1:M
v1=[x2(i,j),x(i,j)];
v2=[y2(i,j),y(i,j)];
v3=[z2(i,j),z(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L-1;
for i=1:M
v1=[x(i,j),x(i,j)];
v2=[y(i,j),y(i,j)];
v3=[z(i,j+1),z(i,j)];
f=line(v1,v2,v3);
end
end
for j=1:L-1;
for i=1:M
v1=[x2(i,j),x2(i,j)];
v2=[y2(i,j),y2(i,j)];
v3=[z2(i,j+1),z2(i,j)];
f=line(v1,v2,v3);
end
end
2D Cylindrical Mesh
clc
clear
M=20;
N=40;
r=1;
r1=1.5;
r2=2;
thet(1)=0;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x(i)=r*cos(theta(i));
y(i)=r*sin(theta(i));
z(i)=0;
end
thet(1)=0;
for i=1:N+1;
dt=360/N;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x1(i)=r1*cos(theta(i));
y1(i)=r1*sin(theta(i));
z1(i)=0;
end
thet(1)=0;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x2(i)=r2*cos(theta(i));
y2(i)=r2*sin(theta(i));
z2(i)=0;
end
plot(x,y,'-*r',x1,y1,'-*k',x2,y2,'-*r');
grid on
axis equal
for i=1:M
v1=[x(i+1),x(i)];
v2=[y(i+1),y(i)];
v3=[z(i+1),z(i)];
f=line(v1,v2,v3);
end
for i=1:N
v1=[x1(i+1),x1(i)];
v2=[y1(i+1),y1(i)];
v3=[z1(i+1),z1(i)];
f=line(v1,v2,v3);
end
for i=1:M
v1=[x2(i+1),x2(i)];
v2=[y2(i+1),y2(i)];
v3=[z2(i+1),z2(i)];
f=line(v1,v2,v3);
end
for i=1:M
v1=[x2(i),x(i)];
v2=[y2(i),y(i)];
v3=[0,0];
f=line(v1,v2,v3);
end
clear
M=20;
N=40;
r=1;
r1=1.5;
r2=2;
thet(1)=0;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x(i)=r*cos(theta(i));
y(i)=r*sin(theta(i));
z(i)=0;
end
thet(1)=0;
for i=1:N+1;
dt=360/N;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x1(i)=r1*cos(theta(i));
y1(i)=r1*sin(theta(i));
z1(i)=0;
end
thet(1)=0;
for i=1:M+1;
dt=360/M;
thet(i+1)=thet(i)+dt;
theta(i)=(pi/180)*thet(i+1);
x2(i)=r2*cos(theta(i));
y2(i)=r2*sin(theta(i));
z2(i)=0;
end
plot(x,y,'-*r',x1,y1,'-*k',x2,y2,'-*r');
grid on
axis equal
for i=1:M
v1=[x(i+1),x(i)];
v2=[y(i+1),y(i)];
v3=[z(i+1),z(i)];
f=line(v1,v2,v3);
end
for i=1:N
v1=[x1(i+1),x1(i)];
v2=[y1(i+1),y1(i)];
v3=[z1(i+1),z1(i)];
f=line(v1,v2,v3);
end
for i=1:M
v1=[x2(i+1),x2(i)];
v2=[y2(i+1),y2(i)];
v3=[z2(i+1),z2(i)];
f=line(v1,v2,v3);
end
for i=1:M
v1=[x2(i),x(i)];
v2=[y2(i),y(i)];
v3=[0,0];
f=line(v1,v2,v3);
end
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com