Cylinder with gyroid infill

9 visualizzazioni (ultimi 30 giorni)
Premysl
Premysl il 13 Giu 2024
Risposto: Arun il 17 Giu 2024
Hello,
I have following matlab code
% Clear all previous commands
clear all
close all
clc
% Variables you can change
SizeL = 20; %average length of RVE
Def = 40; %definition
% Variables you shouldn´t change
SFact = (SizeL/2)/pi; %size factor of RVE
A = SFact*pi; %lowest and max coordinates of meshgrid
D = A/Def; %definition factor
% Generation of gyroids
[X,Y,Z] = meshgrid(-A:D:A); %creates mesh grid
% Gyroid equation
OBJ = cos(X/SFact).* sin(Y/SFact) + cos(Y/SFact).* sin(Z/SFact)...
+ cos(Z/SFact).* sin(X/SFact)+(0);
T = 0.5;
OBJ = (OBJ-T).*(OBJ+T);
% Isosurface and isocap
[F1,V1] = isosurface(X,Y,Z,OBJ,0);
[F2,V2] = isocaps(X,Y,Z,OBJ,0,'below');
%Combines isosurface and isocaps into one
F3 = [F1;F2+length(V1(:,1))];
V3 = [V1;V2];
% Visualization
P = patch('Vertices',V3,'Faces',F3,'FaceColor', ...
'red','EdgeColor','none');
view(3)
camlight
% STL export of independet files per gyroid.
% Change current file path with desired file path.
stlwrite(['C:\...filepath...\G1-T05' num2str(1) '.stl'],F3,V3);
It generates cubical unit cell with gyroid infill. I would need to change it to produce the cylindrical unit cell with height H and radius R with the same infill. I am failing to change the code. Can you help me?
Thank you

Risposte (1)

Arun
Arun il 17 Giu 2024
Hi @Premysi,
I understand that you are looking to convert a cubical unit cell to a cylindrical unit cell with height H and radius R.
To achieve this transformation, utilize the “meshgrid” function and apply mask to the gyroid structure so that it fits within the specified cylindrical domain.
Please find the modified code which might be helpful in producing the desired figure.
% Clear all previous commands
clear all
close all
clc
% Cylinder dimensions
R = 10; % Radius of the cylinder
H = 20; % Height of the cylinder
% Variables you can change
SizeL = 20; %average length of RVE
Def = 40; %definition
% Variables you shouldn´t change
SFact = (SizeL/2)/pi; %size factor of RVE
A = SFact*pi; %lowest and max coordinates of meshgrid
D = A/Def; %definition factor
% Generation of gyroids
[X,Y,Z] = meshgrid(-A:D:A, -A:D:A, linspace(-H/2, H/2, Def)); % Adjusted for cylindrical height
% Convert to cylindrical coordinates to apply mask
[~, rho] = cart2pol(X, Y);
% Gyroid equation
OBJ = cos(X/SFact).* sin(Y/SFact) + cos(Y/SFact).* sin(Z/SFact)...
+ cos(Z/SFact).* sin(X/SFact)+(0);
T = 0.5;
OBJ = (OBJ-T).*(OBJ+T);
% Apply cylindrical mask
OBJ(rho > R) = NaN; % This makes points outside the cylinder NaN, effectively removing them
% Isosurface and isocap
[F1,V1] = isosurface(X,Y,Z,OBJ,0);
[F2,V2] = isocaps(X,Y,Z,OBJ,0,'below');
%Combines isosurface and isocaps into one
F3 = [F1;F2+length(V1(:,1))];
V3 = [V1;V2];
figure;
% Visualization
hold on
P = patch('Vertices',V3,'Faces',F3,'FaceColor', ...
'red','EdgeColor','none');
view(3)
camlight
For additional information related to the “cart2pol” function, please refer to the following MathWorks documentation link: https://www.mathworks.com/help/matlab/ref/cart2pol.html
Hope this helps!
Regards
Arun

Community Treasure Hunt

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

Start Hunting!

Translated by