creating a 3D hexahedral grid from coordinates

7 visualizaciones (últimos 30 días)
Katharina
Katharina el 26 de Ag. de 2022
Respondida: sai charan sampara el 6 de Oct. de 2023
Hey ,
I am trying to create a 3D grid for a finite element problem. I have the x, y and z coordinates of the nodes of a body, and I want to connect them , so that I have hexahedral elements.
In the picture you can see the scatter plot of 12 coordinates, and how I want them to be connected. But I would like to have an alorithm for an arbitray number of coordinates.
Maybe there is someone who can help me.

Respuestas (1)

sai charan sampara
sai charan sampara el 6 de Oct. de 2023
Hello Katharina,
As per my understanding you are trying to create a grid from given set of coordinates.
This can be achieved by connecting the points in such a way that each point is connected to a fixed number of nearest neighbours.
You can iteratively run through the co-ordinates and using distance formula find the 3 nearest neighbours of every point and join them.
%Generating example points
n = 16;
angl_step = 2*pi/n;
alpha = 0:angl_step:2*pi-angl_step;
X = cos(alpha)';
Y = sin(alpha)';
R = sqrt(X.^2 + Y.^2);
X = X + (0.2*R.*sin(3*alpha)'.*cos(3*alpha)');
Y = Y + (0.2*R.*sin(3*alpha)'.*sin(3*alpha)');
Z = sqrt(X.^2 + Y.^2);
p=[X,Y,Z];
%changing order
p = p([end,end-1,1,2:end-2],:);
%algorithm
for i=1:length(p)
dis_array=[];
for j=i+1:length(p)
dis_array=[dis_array,dist(p(i,:),p(j,:))];
end
[~,idx]=sort(dis_array);
hold on
if(~isempty(idx))
a=[p(i,:);p(i+idx(1),:)];
plot3(a(:,1)',a(:,2)',a(:,3)','Marker','o',Color=[0,1,0],LineWidth=2);
end
if(length(idx)>1)
b=[p(i,:);p(i+idx(2),:)];
plot3(b(:,1)',b(:,2)',b(:,3)','Marker','o',Color=[0,1,0],LineWidth=2);
end
if(length(idx)>2)
c=[p(i,:);p(i+idx(3),:)];
plot3(c(:,1)',c(:,2)',c(:,3)','Marker','o',Color=[0,1,0],LineWidth=2);
end
end
hold off
%distance function
function out = dist(p1,p2)
out=sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2+(p1(3)-p2(3))^2);
end
Please refer to the following reference to know about joining the nearest neighbours in 2D space:
Please refer to the following files from file exchange for code like your requirement:
I hope this resolves the issue you were facing.

Categorías

Más información sobre 3-D Scene Control en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by