绘制ply模型顶点的法线(通过两点)

import trimesh
import matplotlib.pyplot as plt

# 读取点云文件
mesh = trimesh.load_mesh('test.ply')

# 计算法线
mesh.vertex_normals

# 创建一个新的图形窗口
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 绘制顶点
ax.scatter(mesh.vertices[:, 0], mesh.vertices[:, 1], mesh.vertices[:, 2], c='b', s=0.5, marker='o')

# 绘制法线
for i in range(len(mesh.vertices)):
    start_point = mesh.vertices[i]
    end_point = mesh.vertices[i] + mesh.vertex_normals[i] * 10
    ax.plot([start_point[0], end_point[0]], [start_point[1], end_point[1]], [start_point[2], end_point[2]], linewidth=2)
      if i > 100:
            break
# 显示图形
plt.show()

效果如下:

 

posted @ 2024-08-28 13:56  hxqmw  阅读(47)  评论(0)    收藏  举报