问题描述
我首先要说这是我的第一个Python项目,我在Matlab上要好得多,所以请多多包涵。我的项目是创建一个切片程序,该程序将使用任何.stl主体并将其替换为任何(现在为bcc)晶格或其他几何表示形式,并创建G代码以在Elegoo Mars [投影]型打印机上进行打印。最终,可以对切片机进行修改,使其也可以在基于激光的打印机上使用。
我打算通过从一个简单的多维数据集(body1.stl)开始并将其替换为具有相同边界的晶格来实现此目的,但是我所做的工作必须适用于我可能打印的任何形状。 / p>
因此,我的第一步是用具有不同XYZ长度的BCC晶格替换多维数据集(body1.stl)。 看来我可以使用以下代码创建BCC晶格来创建顶点:
vh0 = mesh.add_vertex([0,0])
vh1 = mesh.add_vertex([2,0])
vh2 = mesh.add_vertex([0,2,0])
vh3 = mesh.add_vertex([2,0])
vh4 = mesh.add_vertex([0,2])
vh5 = mesh.add_vertex([2,2])
vh6 = mesh.add_vertex([0,2])
vh7 = mesh.add_vertex([2,2])
vh8 = mesh.add_vertex([1,1,1])
所以我的问题是:
- 将这些网格顶点与矢量连接起来的正确方法是什么?以及如何为这些向量分配特定的直径?
- 是否有更好的方法来创建这些顶点?
- 如何有效地将其图案化以适合任何.stl主体?
- 一旦图案化,如何使用.stl主体修剪BCC向量?如何为新顶点分配一个特定的名称,以便可能关闭网格并没有悬空的支腿?
- 修剪前更改X,Y,Z尺寸比例的最佳方法是什么?
这是我用来在进行任何修改之前读入并可视化.stl文件的代码:
import numpy
from stl import mesh
# Using an existing stl file:
your_mesh = mesh.Mesh.from_file('body1.stl')
# Or creating a new mesh (make sure not to overwrite the `mesh` import by
# naming it `mesh`):
# VERTICE_COUNT = 100
# data = numpy.zeros(VERTICE_COUNT,dtype=mesh.Mesh.dtype)
# your_mesh = mesh.Mesh(data,remove_empty_areas=False)
# The mesh normals (calculated automatically)
your_mesh.normals
# The mesh vectors
your_mesh.v0,your_mesh.v1,your_mesh.v2
# Accessing individual points (concatenation of v0,v1 and v2 in triplets)
assert (your_mesh.points[0][0:3] == your_mesh.v0[0]).all()
assert (your_mesh.points[0][3:6] == your_mesh.v1[0]).all()
assert (your_mesh.points[0][6:9] == your_mesh.v2[0]).all()
assert (your_mesh.points[1][0:3] == your_mesh.v0[1]).all()
# your_mesh.save('new_stl_file.stl')
from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
# Create a new plot
figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)
# Load the STL files and add the vectors to the plot
your_mesh = mesh.Mesh.from_file('body1.stl')
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors))
# Auto scale to the mesh size
scale = your_mesh.points.flatten()
axes.auto_scale_xyz(scale,scale,scale)
# Show the plot to the screen
pyplot.show()
谢谢, -艾丽·罗杰斯(Eli Rogers)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)