You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 15:59:49