我正在尝试使用 numpy-stl 从 stl 模型中提取顶点以用于相干点漂移配准。你如何提取顶点?我了解如何从顶点和面列表创建网格,但不知道如何向后创建网格。
我尝试过:从顶点和面创建新的网格。导入创建的网格。
我正在编写一段Python代码,它将接收灰度图像,对其进行缩放,并输出一个3D模型,每个像素的高度由灰度值确定。除了 3d 模型的输出之外,我的一切都正常。我使用 numpy-stl 根据从图像派生的值数组来创建它。使用 numpy-stl 库创建一个框,然后根据图像需要多次复制它。然后我将每一个翻译到与图像相对应的位置和高度。这一切都有效。当我尝试将其全部保存为一个 .stl 文件时,问题就出现了。我不知道如何将立方体的所有单独网格组合成一个。
这里只是处理 3d 数组创建的代码。我可以绘制创建的网格但不能保存它们。
from stl import mesh
import math
import numpy
test = [[1,2],[2,1]]
a = [[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]]
# Create 6 faces of a cube, 2 triagles per face
data = numpy.zeros(12, dtype=mesh.Mesh.dtype)
#cube defined in stl format
# Top of the cube
data['vectors'][0] = numpy.array([[0, 1, 1],
[1, 0, 1],
[0, 0, 1]])
data['vectors'][1] = numpy.array([[1, 0, 1],
[0, 1, 1],
[1, 1, 1]])
# Right face
data['vectors'][2] …Run Code Online (Sandbox Code Playgroud) 我想加载一个 STL 文件并以不同的旋转生成一组 2D 图像。
我根据这个例子获得了使用 numpy-stl 的基础知识,最后得到了这个代码 -
from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
filename = '3001.stl'
# Create a new plot
figure = pyplot.figure()
axes = figure.gca(projection='3d')
# Load the STL files and add the vectors to the plot
mesh = mesh.Mesh.from_file(filename)
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(mesh.vectors, color='lightgrey'))
#axes.plot_surface(mesh.x,mesh.y,mesh.z)
# Auto scale to the mesh size
scale = mesh.points.flatten()
axes.auto_scale_xyz(scale, scale, scale)
#turn off grid and axis from display
pyplot.axis('off')
#set viewing angle
axes.view_init(azim=120) …Run Code Online (Sandbox Code Playgroud)