MATLAB to CAD file
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MATLAB issue.
I have MATLAB code:
clear all
close all
clc
x_period = 4;
y_period = 4;
z_period = 4;
[x,y,z] = meshgrid(0:0.1:x_period*3.14159265359, 0:0.1:y_period*3.14159265359, 0:0.1:z_period*3.14159265359);
f = cos(x).*sin(y) + cos(y).*sin(z) + cos(z).*sin(x);
figure(1)
isosurface(x,y,z,f)
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
fv = isosurface(x,y,z,f)
I want to save file as .xyz or .stl of that gyroid figure, please help me, if it is possible.
If it is not possible then which file can I save so that I can use in solidworks or any CAD software?
0 Commenti
Risposte (2)
Chukwugozie Ejeh
il 22 Lug 2020
Modificato: DGM
il 23 Giu 2025
I am researching on triply periodic minimal surface lattice structures. I have developed a code to save the isosurface data to stl format.
% Initialize Matlab to clear stored data and gain computing speed.
close all; clear all; clc;
% Setting meshgrid
%%%%%%%%%%%%%%%%%%%%%
% generates a row vector L of 100 points linearly spaced between and including 0 and 1.
n = 1; % domain size in the x-direction
L_x = linspace(0, n, 100);
L_y = linspace(0, 1, 100);
L_z = linspace(0, 1, 100);
[X,Y,Z] = meshgrid(L_x, L_y, L_z);
%%%%%%%%%%%%%%%%%%%%%%
a = 2; % constant that controls the periodicity
% Paramertizing the variables
x = a*pi.*X;
y = a*pi.*Y;
z = a*pi.*Z;
c = 0;
% Define the Level-set approimation equation for gyroid (G) and diamond (D)
G = cos(x).*sin(y) + cos(y).*sin(z) + cos(z).*sin(x) - c;
D = cos(0.5.*x).*cos(0.5.*y).*cos(0.5.*z) - sin(0.5.*x).*sin(0.5.*y).*sin(0.5.*z) - c;
% Plotting isosuface
figure (1);
isosurface(X,Y,Z,D,0); % for diamond
% isosurface(X,Y,Z,G,0); % for gyroid
%Writing sheet-network data to stl format by first storing the isovalues (facet and vertex data)
[f,v]=isosurface(X,Y,Z,D,0); stlwrite('sheet.stl',f,v); % for diamond
% [f,v]=isosurface(X,Y,Z,D,0); stlwrite('sheet.stl',f,v); for gyroid
%%% MAKE SURE TO SAVE YOUR STL FILE IN THE SAME DIRECTORY WERE YOUR SAVED THE MATLAB CODE.
3 Commenti
DGM
il 23 Giu 2025
Unless you want to use some of its particular functionality, there isn't a need to complicate things by using FEX #20922. The problem with recommending it is that it will shadow the built-in stlwrite() that's already available in modern versions. If you want to use it, I recommend renaming it to avoid problems.
% ... all the plotting stuff
% you can either call isosurface() again,
% or you can get the existing F,V data from the figure.
[F V] = isosurface(x,y,z,f);
% FEX #20922 accepts multiple input formats
% it can accept F,V lists, an FV struct, or simple gridded data
stlWrite('Gyroid1.stl',F,V) % i renamed this to prevent name collision
% built-in stlwrite() (R2018b or newer) accepts triangulation objects
T = triangulation(F,V);
stlwrite(T,'Gyroid2.stl') % you already have this
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!