How can I write a code for a concentric tube represented by points only?

1 visualización (últimos 30 días)
I want to write a code for a cylindrical tube and a metal strut (see attachment for the shape) represented by points. The code will write the points' position and a bond (link) connecting each point to its neighbour.
See below the example of a rectangular code. I dont know how to write that of cylindrical shape.
clc;
clear;
dL=1;
Nx=5;
Ny=3;
Nz=41;
n = 1;
n_bond_types = 3;
dr_Bond(1) = dL;
dr_Bond(2) = sqrt(2)*dL;
dr_Bond(3) = sqrt(3)*dL;
disp('Atoms Positions');
for i=1:Nx
for j=1:Ny
for k=1:Nz
x(n) = i*dL;
y(n) = j*dL;
z(n) = k*dL;
disp([n, x(n), y(n), z(n)]);
Position(n,1)=n;
Position(n,2)=x(n);
Position(n,3)=y(n);
Position(n,4)=z(n);
n = n+1;
end
end
end
Natoms = n - 1;
disp(['Number of Atoms= ', num2str(Natoms)]);
disp(' ');
nb = 1;
disp('Bonds');
for i=1:Natoms
for j=i+1:Natoms
dx = x(j)- x(i);
dy = y(j)- y(i);
dz = z(j)- z(i);
dr = sqrt(dx^2+dy^2+dz^2);
for k = 1:n_bond_types
if (dr> 0.9999*dr_Bond(k) && dr <1.0000001*dr_Bond(k))
disp([nb, k, i, j]);
nb = nb+1;
end
end
end
end
Nbonds = nb - 1;
disp(['Number of bonds= ', num2str(Nbonds)]);
I will appreciate your kind contributions.
Thank you.
  6 comentarios
darova
darova el 8 de Jul. de 2020
Do you have any attempts? What about spiral equations?
Adamu Mohammed
Adamu Mohammed el 10 de Jul. de 2020
Editada: Adamu Mohammed el 10 de Jul. de 2020
Thank you very much, but like I said earlier I am interested in the points (position) and the link between the points.
I have the following code for a rectangular geometry (see attached) but I don't know how to write that of cylindrical shape.
clc;
clear;
dL=1;
Nx=5;
Ny=3;
Nz=41;
n = 1;
n_bond_types = 3;
dr_Bond(1) = dL;
dr_Bond(2) = sqrt(2)*dL;
dr_Bond(3) = sqrt(3)*dL;
disp('Atoms Positions');
for i=1:Nx
for j=1:Ny
for k=1:Nz
x(n) = i*dL;
y(n) = j*dL;
z(n) = k*dL;
disp([n, x(n), y(n), z(n)]);
Position(n,1)=n;
Position(n,2)=x(n);
Position(n,3)=y(n);
Position(n,4)=z(n);
n = n+1;
end
end
end
Natoms = n - 1;
disp(['Number of Atoms= ', num2str(Natoms)]);
disp(' ');
nb = 1;
disp('Bonds');
for i=1:Natoms
for j=i+1:Natoms
dx = x(j)- x(i);
dy = y(j)- y(i);
dz = z(j)- z(i);
dr = sqrt(dx^2+dy^2+dz^2);
for k = 1:n_bond_types
if (dr> 0.9999*dr_Bond(k) && dr <1.0000001*dr_Bond(k))
disp([nb, k, i, j]);
nb = nb+1;
end
end
end
end
Nbonds = nb - 1;
disp(['Number of bonds= ', num2str(Nbonds)]);

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by