我正在分析小鼠胚胎中心脏发育区域的形状变化。为此,我研究了该组织内细胞的空间坐标如何随时间变化。
我正在使用函数matplotlib.plot_trisurf
获得这些单元格的坐标之间的三角化表面:
现在,我想计算该三角表面的面积并将该表面提取为.stl
文件,以便可以在MeshLab
等其他3D浏览器中使用。我不知道该怎么做。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
##Data, spatial coordinates for each of the cells forming the tissue.
X = np.array([157.68627725, 103.11761198, 157.51873667, 165.81563644,
77.9816598 , 126.77531671, 90.24263806, 162.27734804,
122.62725478, 83.2503042 , 162.59702484, 88.3921336 ])
Y = np.array([-174.21831735, -144.38094418, -144.87819434, -181.84569162,
-116.19711147, -133.53935007, -139.02422794, -141.49550572,
-137.70714927, -144.36804192, -174.05904052, -120.61181162])
Z = np.array([-40.21972608, 19.97958051, -49.49361177, -69.6049367 ,
-10.5853926 , -22.06279801, 23.51722221, -72.24126518,
8.24172533, 42.0251029 , -49.31600354, -16.93026202])
##Plot triangulated surface
fig = plt.figure(figsize = (10, 4.5))
ax = fig.add_subplot(121, projection = '3d')
ax.plot_trisurf(X,Y,Z)
surface.save('mysurface.stl', ax.plot_trisurf(X,Y,Z))
surface.calculate_area(ax.plot_trisurf(X,Y,Z))
我在Google上找到了此解决方案,它对我有用。就我而言,我在绘制之前进行了三角剖分。之前安装库numpy-stl(https://github.com/WoLpH/numpy-stl)。然后,尝试添加以下代码:
import stl
from stl import mesh
triang=triangulation(x,y,z)
data = np.zeros(len(triang.triangles), dtype=mesh.Mesh.dtype)
mobius_mesh = mesh.Mesh(data, remove_empty_areas=False)
mobius_mesh.x[:] = x[triang.triangles]
mobius_mesh.y[:] = y[triang.triangles]
mobius_mesh.z[:] = z[triang.triangles]
mobius_mesh.save('mysurface.stl')