Defining nodal coordinates for a 3D cubic lattice.

32 次查看(过去 30 天)
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.

采纳的回答

Samuel Thompson
Samuel Thompson 2017-10-2
编辑:Samuel Thompson 2017-10-3
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 个评论
MD SHARIER
MD SHARIER 2023-12-20
It doesn't seem to be working.Is there any updated version of it?
DGM
DGM 2023-12-21
编辑:DGM 2023-12-21
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])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by