我试图找到 3d 对象 .stl 文件(我使用 numpy-stl 导入到 python)和 3d 绘图(我使用 matplotlib 生成)之间的交点。3d 对象是 cad 绘图,3d 绘图是 3d 中的一堆曲线。我可以将它们绘制在同一个图上,但我不知道如何找到轨迹和绘图之间的交点。我的想法是在绘制曲线后使用 numpy-stl 模块中的 save() 函数将曲线转换为 .stl,并将它们一起显示在像 freeCAD 这样的 cad 应用程序上,并使用应用程序的功能找到交点。但它并不那么简单,因为这些图是基于点的,而 .stl 是基于三角形的。如果有人对如何解决这个问题有任何建议,请告诉我!!
这是绘制 .stl 对象和 3d 绘图的代码。这就是我到目前为止所拥有的。
#allInitialE is 1D list, allX, allY, allZ are all 2D lists
from stl import mesh
from numpy import *
from mpl_toolkits import mplot3d
from matplotlib import pyplot as plt
fig = plt.figure()
ax = plt.axes(projection = '3d')
your_mesh = mesh.Mesh.from_file('fileName.stl')
your_mesh.translate([0,7,0])
ax.add_collection3d(mplot3d.art3d.Poly3DCollection(your_mesh.vectors))
ax.view_init(azim = -90, elev = 0)
maxE = max(allInitialE)
ax.set_xlabel('x axis (m)') # y and z are flipped to make it easier for me to visualize
ax.set_ylabel('z axix (m)')
ax.set_zlabel('y axix (m)')
plt.title('Particle Trajectory')
for k in range(numParticles): #iterate through each of the particles' xyz data
e = allInitialE[k]
if e < maxE/3:
ax.plot3D(allX[k], allZ[k], allY[k], 'g-')
elif e < maxE/2:
ax.plot3D(allX[k], allZ[k], allY[k], 'b-')
else:
ax.plot3D(allX[k], allZ[k], allY[k], 'r-')
plt.show()
1个想法:有没有办法将.stl对象转换为一组平面函数?如果是这样,我可以将绘图变成线并找到平面和线之间的交点?
第二个想法:或者,因为 .stl 是基于矢量的,我可以使用矢量计算?即查看曲线(线段)上的向量是否与 .stl 对象上的三角形有共同点(三角形由三个向量定义)。
请给我任何你可能有的想法!太感谢了。