フィルターのクリア

Is it possible to 3D print a 3D function plotted in Matlab?

16 ビュー (過去 30 日間)
Lewis HC
Lewis HC 2023 年 7 月 12 日
回答済み: Cris LaPierre 2023 年 7 月 13 日
Greetings to all, I am trying to convert a 3D function plotted in Matlab (or convert it to STL file) to be able to print it in 3D, I am using the stlwrite command but it does not work, I attach my code, I appreciate any suggestions:
% Define your 3D function (example: parabolic function)
a = 1;
b = 2;
c = 3;
myFunction = @(x, y) a*x.^2 + b*y.^2 + c;
% Generate a mesh
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
Z = myFunction(X, Y);
% Triangulate the mesh
triangulation = delaunayTriangulation(X(:), Y(:), Z(:));
% Save the triangulated mesh as an STL file
filename = 'my_mesh.stl';
stlwrite(filename, triangulation.ConnectivityList, triangulation.Points);
  2 件のコメント
Star Strider
Star Strider 2023 年 7 月 12 日
Please go ito a bit of detail about the problem. What does ‘it does not work’ mean? What is the result of using stlwrite?
Rahul
Rahul 2023 年 7 月 12 日
Please make sure that the stlwrite function is correctly downloaded and it's path has been set correctly.

サインインしてコメントする。

回答 (3 件)

Niranjan Sundararajan
Niranjan Sundararajan 2023 年 7 月 12 日
Not an official implementation of stlwrite but it works. Paste the function in your current working directory and rename it stlwrite. Then, you can call it by using:
stlwrite(filename, X, Y, Z);
It will work.

Cris LaPierre
Cris LaPierre 2023 年 7 月 12 日
編集済み: Cris LaPierre 2023 年 7 月 12 日
Your syntax for stlwrite is not correct. It should be stlwrite(TR,filename)
However, the input triangulation must be a triangulation object or 2-D delaunayTriangulation object. You are using a 3D delaunay triangulation.
Finally, there is no thickness to your object, which will prevent it from being able to be 3D printed.
  2 件のコメント
Niranjan Sundararajan
Niranjan Sundararajan 2023 年 7 月 13 日
stlwrite does not work for 3-D implementation currently in the MATLAB function. And author of this question wants to plot 3-D stl file. Is there some official MATLAB implementation for the same.
Cris LaPierre
Cris LaPierre 2023 年 7 月 13 日
They do not want to plot it. They want to save it to an STL file and 3D print it.

サインインしてコメントする。


Cris LaPierre
Cris LaPierre 2023 年 7 月 13 日
This may be what @Niranjan Sundararajan is referring to. In that thread, the accepted answer suggests using the file exchange stlwrite function to create a 3D stl.
Here is code that works for me:
% Define your 3D function (example: parabolic function)
a = 1;
b = 2;
c = 3;
myFunction = @(x, y) a*x.^2 + b*y.^2 + c;
% Generate a mesh
x = linspace(-10, 10, 5);
y = linspace(-10, 10, 5);
[X, Y] = meshgrid(x, y);
Z = myFunction(X, Y);
% Triangulate the mesh
TR = delaunayTriangulation(X(:),Y(:),Z(:))
TR =
delaunayTriangulation with properties: Points: [25×3 double] ConnectivityList: [58×4 double] Constraints: []
figure
tetramesh(TR)
% Save the triangulated mesh as an STL file
filename = 'my_mesh.stl';
stlwrite(filename,X,Y,Z);

カテゴリ

Help Center および File ExchangeSTL (STereoLithography) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by