在Matlab中打开STL文件

问题描述 投票:0回答:1

我提取了STL文件中顶点的坐标,并使用这些简单的代码来可视化3D模型:

for i=0:214
 fill3(A(:,i*7+3),A(:,i*7+4),A(:,i*7+5),'b');
 grid on; hold on; alpha(0.3)
end

3D模型是具有214个三角形的球形对象,但是我得到了:enter image description here

怎么了?

matlab 3d stl
1个回答
0
投票

您没有将曲面数据提供给fill3,因此没有明确定义的三角剖分,并且正试图在连续的顶点之间填充(可能没有特定的顺序)。

您可以使用convhull之类的函数来重新创建表面数据(如果对象是凸的,请参见以下示例:

或者,由于您具有STL文件,因此您可能已经可以使用trisurf使用三角测量数据。

plots

% Create points on a sphere
N = 200;
TH = 2*pi*rand(1,N).';
PH = asin(-1+2*rand(1,N)).';
A = NaN(N,3);
[A(:,1),A(:,2),A(:,3)] = sph2cart(TH,PH,1);

% Plotting
figure(5); clf

subplot(1,3,1);
plot3(A(:,1),A(:,2),A(:,3),'.');
grid on; title( 'plot3' );

subplot(1,3,2);
fill3(A(:,1),A(:,2),A(:,3),'b');
grid on; title( 'fill3' );

subplot(1,3,3);
Tri = convhull(A(:,1),A(:,2),A(:,3));
trisurf(Tri,A(:,1),A(:,2),A(:,3),'Facecolor','b');
grid on; title( 'trisurf / convhull' );
© www.soinside.com 2019 - 2024. All rights reserved.