STL to MatLab coordinates conversion (?)

조회 수: 29 (최근 30일)
J
J 2015년 5월 20일
편집: DGM 2025년 3월 31일
Hi, I'm looking for some potential guidance on a project I'm currently working on.
I'm attempting to take STL files and more or less convert the STL file into coordinates/points (in a 3D array?) in MatLab, into something that can be plotted to create the original picture (including points inside the image too) out of the points/coordinates/array(s).
I've spent multiple hours looking at different open source codes that somewhat assist in my endeavors (STL to mesh voxelization, etc.), but nothing seems to offer full guidance on how to get to my end goal.
The mesh voxeliser (<http://www.mathworks.com/matlabcentral/fileexchange/27390-mesh-voxelisation>) seems to only give surface/face/vertices coordinates and for some reason it doesn't seem like it gives points inside of objects (STL files).
I would be so monumentally grateful for any thorough advice/guidance/insight on this; I've entered into relatively new waters within MatLab for this project so this is a learning experience for me.
Thank you very much for taking the time to read this and for any response.
  댓글 수: 3
michio
michio 2016년 9월 3일
As far as I understand, STL file contains only the surface coordinates.
If you want to generate a list of coordinates/points of the 3D object that is defined by STL file including inside the object, you might want to "generate" the coordinates/points within the object.
I can think of two ways
1: Generate a fine distribution of 3D point cloud and find which of those are within the object.
2: Use FEM meshing functionality (PDE Toolbox or other software possibly including File Exchange entries).

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

답변 (1개)

DGM
DGM 2025년 3월 31일
편집: DGM 2025년 3월 31일
FEX #27390 comes with a complete demo, including a sample STL file and reader utility. I think OP was looking at the wrong file.
That said, maybe this is a clearer example:
unzip holesphere2.stl.zip % needed on the forum
% get the object to visualize it
% stlread() wasn't available until R2018b, but there were other readers.
% this is only used for visualization anyway. it's not strictly necessary.
fname = 'holesphere2.stl';
T = stlread(fname);
% visualize the object
% note the orientation of the object features:
% object is a 30mm sphere, centered on the origin
% there is a 10mm square through-hole along z
% there is a half-depth 10mm round hole along +x
% there is a half-depth 5mm round hole along +y
% there is a partial top cut roughly in the first octant of the sphere
figure(1)
hp = patch('faces',T.ConnectivityList,'vertices',T.Points,'facecolor','w','edgecolor','none');
view(3)
camlight
axis equal
view(112,36)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
% voxelize the shape
% you can either provide per-axis decimation factors,
% or you can provide explicit sampling vectors for each axis.
%vv = linspace(-15,15,50); % xyz sampling vectors are the same due to object symmetry
%[voxvolume gx gy gz] = VOXELISE(vv,vv,vv,fname,'xyz');
% OR:
d = 50; % subdivide the circumscribed cuboid by this factor
[voxvolume gx gy gz] = VOXELISE(d,d,d,fname,'xyz');
% the result is a 50x50x50 logical array describing the volume enclosed by
% the object in the STL file. the vectors gx,gy,gz define the grid on
% which the object was sampled.
% visualize projections of the voxelized object:
% along Z
% note the two half-depth holes extending along +x and +y
figure(2)
xyproj = permute(sum(voxvolume,3),[2 1 3]);
imagesc(gx,gy,xyproj)
set(gca,'ydir','normal')
axis equal tight
xlabel('X')
ylabel('Y')
% along Y
% now the 5mm hole is on-axis
figure(3)
xzproj = permute(sum(voxvolume,2),[3 1 2]);
imagesc(gx,gz,xzproj)
set(gca,'ydir','normal')
axis equal tight
xlabel('X')
ylabel('Z')
% along X
% now the 10mm hole is on-axis
figure(4)
yzproj = permute(sum(voxvolume,1),[3 2 1]);
imagesc(gy,gz,yzproj)
set(gca,'ydir','normal')
axis equal tight
xlabel('Y')
ylabel('Z')
You can also use isosurface() or volshow(), etc to view the volumetric data.

카테고리

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