A Simple Cylinder Mesh Generator for Panel Method by MATLAB

Meshing a body surface and definition of the panel distribution are the previous steps when using linear radiation/diffraction panel codes for studying hydrodynamics. A cylinder mesh generator and panel distribution approach is provided by this post.

``````R=3;   % radius of cylinder
H=-20; % cylinder height, negative quantity means the draft
Nr=15; % No. of nodes in radius direction
Nt=20; % No. of nodes in circuferential direction
Nz=25; % No. of nodes in vertical direction

nodes=zeros(Nt*(Nz-1)+Nt*Nr+1,3); %total nodes' coodinate
triangles=zeros(Nt,3);            %triangular panels

% bottom center
c=1;
nodes(c,1)=0.0;
nodes(c,2)=0.0;
nodes(c,3)=H;

%bottom surface
for j=1:Nr %
for i=1:Nt %
c=c+1;
nodes(c,1)=R*j/Nr*cosd(360*(i-1)/Nt);
nodes(c,2)=R*j/Nr*sind(360*(i-1)/Nt);
nodes(c,3)=H;
end
end

% side wall
for j=1:Nz-1
for i=1:Nt
c=c+1;
nodes(c,1)=R*cosd(360*(i-1)/Nt);
nodes(c,2)=R*sind(360*(i-1)/Nt);
nodes(c,3)=H-H/(Nz-1)*j;
end
end

%Triangles panel
%------------
nt=0;
for i=2:Nt % right-hand rule, and direct downward
nt=nt+1;
triangles(i-1,1)=i+1;
triangles(i-1,2)=i;
triangles(i-1,3)=1;
end
nt=nt+1;
i=i+1;
triangles(i-1,1)=2;
triangles(i-1,2)=i;
triangles(i-1,3)=1;

%------------
%bottom
nq=0;
for j=1:Nr-1
for i=2:Nt
nq=nq+1;
end
nq=nq+1;
i=i+1;
end

% wall
for j=1:Nz-1
for i=2:Nt
nq=nq+1;