Is there a reason why my stl file isn't being read correctly?

16 ビュー (過去 30 日間)
Jaime Castiblanques
Jaime Castiblanques 2021 年 3 月 17 日
I have a code that reads stl files created in Inventor and plots them. Although it works well for some parts, there are some with which stlread has trouble. Instead of plotting the correct surface, it deforms it. My code is:
% Reads the file
data=stlread('Countercurves.stl');
x = data.Points(:,1);
y = data.Points(:,2);
z = data.Points(:,3);
%Meshing of the file
DT = delaunayTriangulation(x,y,z);
[Tfb,Xfb] = freeBoundary(DT);
TR = triangulation(Tfb,Xfb);
V = vertexNormal(TR);
%Plots the surface with the surface normals
figure
trisurf(TR,'FaceColor','cyan','FaceAlpha', 0.8);
axis equal
hold on
quiver3(Xfb(:,1),Xfb(:,2),Xfb(:,3), ...
V(:,1),V(:,2),V(:,3),0.5,'Color','r');
xlabel('X direction');
ylabel('Y direction');
zlabel('Z direction');
In the good cases, I get something like the following hemiellipsoid, whereas in the bad ones, I get the figure below:
The latter should be a sinusoidal surface. However, for some reason the spaces are filled in, and the code plots the surface normals of the edges. Any help?
  6 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 4 月 2 日
編集済み: Cris LaPierre 2021 年 4 月 2 日
Yes, now I do. stlread is loading the stl files just fine. It is your code to extract the surface normals that seems to be the issue.
unzip('stls.zip');
data=stlread('Countercurves.stl');
trisurf(data)
figure
data2=stlread('SingleCurvature_r100.stl');
trisurf(data2)
It looks like you are duplicating the information already contained in an stl file. Try simplifying your code to the following (after loading the file).
%Meshing of the file
V = vertexNormal(data);
%Plots the surface with the surface normals
figure
trisurf(data,'FaceColor','cyan','FaceAlpha', 0.8);
axis equal
hold on
quiver3(data.Points(:,1),data.Points(:,2),data.Points(:,3), ...
V(:,1),V(:,2),V(:,3),0.5,'Color','r');
hold off
xlabel('X direction');
ylabel('Y direction');
zlabel('Z direction');
I've gone this far, so we might as well see what it looks like for the other stl file you shared.
%Meshing of the file
V = vertexNormal(data2);
%Plots the surface with the surface normals
figure
trisurf(data2,'FaceColor','cyan','FaceAlpha', 0.8);
axis equal
hold on
quiver3(data2.Points(:,1),data2.Points(:,2),data2.Points(:,3), ...
V(:,1),V(:,2),V(:,3),0.5,'Color','r');
hold off
xlabel('X direction');
ylabel('Y direction');
zlabel('Z direction');
Jaime Castiblanques
Jaime Castiblanques 2021 年 4 月 3 日
Hello Cris,
This has solved my problem. I had not realized I was duplicating the data, so thank you for pointing that out.

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

採用された回答

Bruno Luong
Bruno Luong 2021 年 4 月 1 日
編集済み: Bruno Luong 2021 年 4 月 1 日
You should not use delaunayTriangulation to make connectiviy of the points. It creates a convex hull of all the points.
Usualy the connectivity is from structure read from the file.
  2 件のコメント
Jaime Castiblanques
Jaime Castiblanques 2021 年 4 月 1 日
Oh I see. How can I do the connectivity then?
Bruno Luong
Bruno Luong 2021 年 4 月 2 日
編集済み: Bruno Luong 2021 年 4 月 2 日
See Cris answer, he plots TRISURF directly from the data structure read from file.
The STL data has a list of point AND the connectivity.
Please inspect the structure returns by stlread and read documentation of TRISURF.

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

その他の回答 (0 件)

カテゴリ

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