如何在trimesh中以面片中心为起点绘制面片法线?
解决Trimesh面片法线起点改为面片中心的问题
你提到的triangles_center正是每个三角面片的中心坐标——Trimesh创建的网格默认是三角化结构,所以直接用这个属性替换原代码中的facets_origin,就能让法线从面片中心出发。
修改后的完整代码如下:
import numpy as np import trimesh mesh = trimesh.creation.torus(9, 3) # 用三角面片中心作为法线起点 vec = np.column_stack((mesh.triangles_center, mesh.triangles_center + (mesh.facets_normal * mesh.scale * .05))) path = trimesh.load_path(vec.reshape((-1, 2, 3))) trimesh.Scene([mesh, path]).show(smooth=False)
关键说明
mesh.triangles_center返回的是每个三角面片的几何中心(三个顶点坐标的平均值),完全匹配你需要的“面片中心”定位需求。- 仅替换起点坐标,法线方向(
facets_normal)和长度缩放逻辑保持不变,确保可视化效果符合预期。
内容的提问来源于stack exchange,提问作者Vlas Sokolov
相关产品推荐
相关产品推荐

