Defining nodal coordinates for a 3D cubic lattice.

20 Ansichten (letzte 30 Tage)
Samuel Thompson
Samuel Thompson am 29 Sep. 2017
Bearbeitet: DGM am 21 Dez. 2023
Hi,
I wish to create a 3D lattice formed by joining together many 8-node cubic elements (see figure). I wish to define the number of cubic elements I want in the x, y and z direction whilst also being able to obtain the coordinates for each node in an array C. Where C(:,1) refers to the x coordinates, C(:,2) refers to the y and C(:,3) to the z and where C(1,:) refers to the first node, C(2,:) the second etc.
My script thus far is attached. I am struggling with two key issues:
  1. Creating a loop that adds additional elements with the correct node assignments.
  2. Assuring that the code is robust such that the entire structure maintains its cubic/cuboidal shape despite varying user inputs.
Any help would very much be appreciated.
Sam
Note: The figure represents the desired output when the user defines 2 elements in the x, y and z axis.
Note: This figure denotes the preferred node arrangement for a 3x2x1 cubic lattice.

Akzeptierte Antwort

Samuel Thompson
Samuel Thompson am 2 Okt. 2017
Bearbeitet: Samuel Thompson am 3 Okt. 2017
For those who this may be useful, I modified a code provided from another MATLAB user, Marten for ease of use. https://uk.mathworks.com/matlabcentral/fileexchange/48373-stl-lattice-generator?s_tid=srchtitle
Find the code attached.
  2 Kommentare
MD SHARIER
MD SHARIER am 20 Dez. 2023
It doesn't seem to be working.Is there any updated version of it?
DGM
DGM am 21 Dez. 2023
Bearbeitet: DGM am 21 Dez. 2023
Looks like it works just fine to me.
%% CUBE COORDINATE MAPPING TRIALS
clc
clearvars
O = [0 0 0];% origin
Nx = 3; % defines number of elements in x direction
Ny = 3; % defines number of elements in y direction
Nz = 3;
Lx = 1; % defines length of single element in x direction
Ly = 1; % defines length of single element in y direction
Lz = 1; % defines length of single element in z direction
%% COORDINATES FOR BODY-CENTERED CUBIC (BCC) ELEMENT
nodes = [O; O(1)+Lx, O(2), O(3); O(1)+Lx, O(2)+Ly, O(3); O(1), O(2)+Ly, O(3);...
O(1), O(2), O(3)+Lz; O(1)+Lx, O(2), O(3)+Lz; O(1)+Lx, O(2)+Ly, O(3)+Lz;...
O(1), O(2)+Ly, O(3)+Lz; O(1)+Lx/2, O(2)+Ly/2, O(3)+Lz/2];
no_nodes = length(nodes);
%% LATTICE NODES
% cell replication - produce every node in lattice (including duplicates)
for nix=1:Nx-1 %Modified to include variable number of nodes for each cell type
for i=1:no_nodes
nodes(no_nodes+no_nodes*(nix-1)+i,:)=[nodes(i,1)+nix*Lx,nodes(i,2),nodes(i,3)];
end
end
for niy=1:Ny-1
for i=1:no_nodes*Nx
nodes(no_nodes*Nx+no_nodes*Nx*(niy-1)+i,:)=[nodes(i,1),nodes(i,2)+niy*Ly,nodes(i,3)];
end
end
for niz=1:Nz-1
for i=1:no_nodes*Nx*Ny
nodes(no_nodes*Nx*Ny+no_nodes*Nx*Ny*(niz-1)+i,:)=[nodes(i,1),nodes(i,2),nodes(i,3)+niz*Lz];
end
end
%% Remove duplicate nodes
[C,~,~]=unique(nodes,'rows');
%% SCATTER NODES
figure
scatter3(C(:,1),C(:,2),C(:,3),'rx');
hold on
C1 = C(:,1); C2 = C(:,2); C3 = C(:,3);
for k=1:length(C)
text(C1(k),C2(k),C3(k),num2str(k))
end
daspect([1 1 1])
xlabel('xaxis'); ylabel('yaxis'); zlabel('zaxis');
% xlim([-0.5*L,Nx])
% ylim([-0.5*L,Ny])
% zlim([-0.5*L,2])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by