How to export a 3D surface (gyroid) as an stl file

조회 수: 20 (최근 30일)
Daniel Tomas Gardner Cuesta
Daniel Tomas Gardner Cuesta 2019년 12월 19일
편집: DGM 2025년 6월 22일
Hi,
I'm a final year Mechanical Engineering student and for my final year project I'm studying the deformational behaviour of gyroids under several loading conditions. Currently I have managed to create a the gyroid's surface but I'm struggling to export the surface as an stl file. I've tried using the stlwrite function but it gives an error message saying "Input argument must be a triangulation object". I then tried to triangulate the gyroid surface using several methods but was unsuccessful. Here is the code:
clear all
close all
clc
x_period = 4;
y_period = 4;
z_period = 4;
% Setting meshgrid
[x, y, z] = meshgrid(0:0.1:x_period*pi, 0:0.1:y_period*pi, 0:0.1:z_period*pi)
% Gyroid equation
v = cos(x).*sin(y) + cos(y).*sin(z) + cos(z).*sin(x);
figure(1)
isosurface(x,y,z,v)
axis equal
xlabel ('X')
ylabel ('Y')
zlabel ('Z')
hold on
Any idea how I could save this figure as an stl file?
Thanks
  댓글 수: 2
darova
darova 2019년 12월 19일
Read how to use isosurface (extract faces and nodes)
迪迪 赵
迪迪 赵 2021년 11월 24일
I have the same problem. Have you solved it? Can you tell me how to solve it? thank you!

댓글을 달려면 로그인하십시오.

답변 (2개)

Henrique Ramos
Henrique Ramos 2020년 5월 2일
Dear Daniel
Use the stlwrite export (file exchange), find for download at,
set the .m file at the same path, and run this code, at the your .m (gyroid)
fv = isosurface(x,y,z,v);
stlwrite('Gyroid.stl',fv)
  댓글 수: 5
MITHILESH KURUP
MITHILESH KURUP 2022년 2월 16일
Hello Henrique,
The file stlwrite from the link and the main code, both are in the same folder only.
But, unfortunately it is still giving the same error as before:
Unable to write to Gyroid.stl
The version that I'm using is MATLAB R 2021 b. Could it be due to the current version that I'm using?
Thanks
DGM
DGM 2025년 6월 22일
편집: DGM 2025년 6월 22일
The given error message indicates that you're trying to write somewhere where you don't have permissions, or you're trying to overwrite a read-only file.
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 FV data from the figure.
FV = 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',FV) % i renamed this to prevent name collision
% built-in stlwrite() (R2018b or newer) accepts triangulation objects
T = triangulation(FV.faces,FV.vertices);
stlwrite(T,'Gyroid2.stl') % you already have this
I should point out that in the end, the given code will produce a surface, not a solid volume. It has no thickness, so depending on what you want to do with it, it might not work as you need it to.

댓글을 달려면 로그인하십시오.


DGM
DGM 2025년 6월 22일
See the full example here:
This example produces a closed model, but it simplifies if you only want an open shell.

카테고리

Help CenterFile Exchange에서 STL (STereoLithography)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by