将Stl转换为numpy数组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Stl转换为numpy数组相关的知识,希望对你有一定的参考价值。

有没有办法将stl文件内容转换为numpy数组或一组numpy数组?

我知道我总是可以将stl作为文件读取然后分配变量,但我想知道是否有自动化方式!

答案

试试numpy-stl包。

pip install numpy-stl之后:

import numpy
from stl import mesh

# Using an existing stl file:
your_mesh = mesh.Mesh.from_file('some_file.stl')
另一答案

我建议使用trimesh。这是一个示例脚本:

from trimesh import Trimesh
from trimesh import voxel
mesh = Trimesh()
mesh.vertices=vertices
mesh.faces=faces
array = voxel.VoxelMesh(mesh=mesh, pitch=1).matrix_solid

以上是关于将Stl转换为numpy数组的主要内容,如果未能解决你的问题,请参考以下文章