Convert 3D coordinates to stl surface

So I have an issue from coordinate data[X,Y,Z]. It appears you can use stlwrite to readily convert vertice and face data or X,Y 2D delaunay triangulated graphs to stl files however, since I only have coordinate data [X,Y,Z] I cannot convert the delaunay triangulated object to an stl file because the delaunay functions convert it into tetrahedron instead of a 3D surface. Is there any solution to generate a surface from XYZ coordinate data and export out as an STL file? I cannot seem to find a solution unless there is already facet and vertice data.
Edit: Looks like boundary facets can give me what I'm looking for
Current implementation
X = table(:,1)
Y = table(:,2)
Z = table(:,3)
tri = delaunaytriangulation(X,Y,Z);
stlwrite(tri, 'filename.stl','ascii')

2 件のコメント

darova
darova 2019 年 9 月 23 日
Please attach your data
Bewler
Bewler 2019 年 9 月 24 日
編集済み: darova 2020 年 6 月 17 日
Here's the data.
I can seem to do
tri = delaunay(X,Y);
trisurf(tri,X,Y,Z);
and it comes out perfectly with heights and transitions and faces between the triangles...
When I try to plot it as an stl, the faces are very incorrect however the coordinate data is correct
tri = delaunay(X,Y,Z);
stlPlot(dataTable,tri, 'stlplot')

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

回答 (3 件)

Fabio Freschi
Fabio Freschi 2019 年 9 月 25 日

1 投票

I don't know where the stlPlot function comes from, so I cannot replicate your problem. Anyway, your call
tri = delaunay(X,Y,Z);
Creates a delaunay triangulation with 3d simplexes, e.g. with tetrahedra (four-node volume elements). Maybe this is why you get the wrong result.

4 件のコメント

Bewler
Bewler 2019 年 9 月 25 日
編集済み: Bewler 2019 年 9 月 25 日
So my current code actually uses
tri = delaunay(X,Y);
and
trisurf(tri,X,Y,Z);
and the result is
Is there no way to convert tedtrahedron into an stl file? I assume tetrahedrons are the mesh that most 3D CAD programs use in FEA so that form of a converted file may work as well rather than an stl. I also don't quite understand the nodes (3 vs 4) and faces(connectivity lists) and how the stl builds from these lists.
Fabio Freschi
Fabio Freschi 2019 年 9 月 25 日
You can get the surface faces of the tetrahedra with
% tet delaunay
tri = delaunayTriangulation(X,Y,Z);
% get surface faces and nodes
[F,P] = freeBoundary(tri);
% plot with trisurf
figure
trisurf(F,P(:,1),P(:,2),P(:,3),'FaceColor','red');
% or use patch
figure
patch('Faces',F,'Vertices',P,'FaceColor','red');
Fabio Freschi
Fabio Freschi 2019 年 9 月 25 日
In your case it is maybe better to triangulate the surface in the xy plane
% triangulate in xy
T = delaunay(X,Y);
% create triangulation in 3d
tri = triangulation(T,X,Y,Z);
% plot
patch('Faces',tri.ConnectivityList,'Vertices',tri.Points,'FaceColor','red')
% now save
stlwrite(tri,'mytriangulation.stl');
tar abu
tar abu 2020 年 6 月 17 日
hey
can you please send me the stl file.
i need it in "nameofthefile.stl"
thank you

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

darova
darova 2019 年 9 月 25 日

0 投票

I took your data and did this:
A = xlsread('data.xlsx');
X = A(:,1);
Y = A(:,2);
Z = A(:,3);
stlwrite('file.stl',X,Y,Z)
fv = stlread('file.stl')
patch(fv,'FaceColor', [0.8 0.8 1], ...
'EdgeColor', 'none', ...
'FaceLighting', 'flat', ...
'CDataMapping', 'direct', ...
'AmbientStrength', 0.5);
camlight
axis equal
Is it wrong?
img1.png

3 件のコメント

Bewler
Bewler 2019 年 9 月 25 日
So when I try that code it says
Error using stlwrite (line 25)
Input argument must be a triangulation object.
Anyhow, this is what I'm looking to generate in an stl file
Capture - Copy.PNG
darova
darova 2019 年 9 月 25 日
I downloaded stlwrite() from HERE
Bewler
Bewler 2019 年 9 月 25 日
It says patch doesn't have enough input arguments. I'm still trying to see the stl file.

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

FRANCESCO OTTAVIANI
FRANCESCO OTTAVIANI 2022 年 12 月 19 日

0 投票

This code worked in my case
clear global;
A = readmatrix('point3d.txt');
B = unique(A,'rows');
X = B(:,1);
Y = B(:,2);
Z = B(:,3);
% triangulate in xy
T = delaunay(X,Y);
% create triangulation in 3d
tri = triangulation(T,X,Y,Z);
% plot
patch('Faces',tri.ConnectivityList,'Vertices',tri.Points,'FaceColor','red')
% now save
stlwrite(tri,'point3d.stl');

製品

リリース

R2018a

質問済み:

2019 年 9 月 23 日

回答済み:

2022 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by