python - 将 3D 曲面(由 plot_trisurf 生成)投影到 xy 平面并在 2D 中绘制轮廓
问题描述
我有一组这种格式的点云:
x = [1.2, 1.3, .....]
y = [2.1, 1.2, .....]
z = [0.5, 0.8, .....]
我plot_trisurf
用来绘制(通过 Delauney 三角测量)“代表”点云的 3D 表面。
我的问题是:是否有一种快速/体面的方法可以将生成的曲面plot_trisurf
投影到 xy 平面,并且只将投影的轮廓绘制为 2D 图?
例如,假设我在点云中的所有点都在一个球面上,那么plot_trisurf
将为我绘制一个(不是那么完美的)球体。然后我的目标是将这个球体“投影”到 xy 平面,然后将其轮廓绘制为2D图(这是一个圆圈)。
编辑:
请注意,此2D 图是 2D 曲线(可能是闭合曲线)。
解决方案
您可以使用trimesh
或类似的模块来快速实现您的目标,而无需重新发明轮子,因为此类库已经实现了处理网格的方法。
请参阅下面将曲面投影到任意平面上的快速实现,该平面由其法线向量和原点定义。
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import trimesh
mesh = trimesh.load('./teapot.obj')
triangles = mesh.faces
nodes = mesh.vertices
x = nodes[:,0]
y = nodes[:,2]
z = nodes[:,1]
# Section mesh by an arbitrary plane defined by its normal vector and origin
section = mesh.section([1,0,1], [0,0,0])
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, z, triangles=triangles, color=(0,1,0,0.3), alpha=0.3)
ax.scatter(section.vertices[:,0], section.vertices[:,2], section.vertices[:,1])
plt.axis([-3, 3, -3, 3])
plt.show()
希望这能有所帮助!
推荐阅读
- javascript - 冲浪后丢失参考创建窗口
- java - 一切看起来都很完美,但 Eclipse 安装程序无法安装,原因是找不到 JDK
- reactjs - 在我的 React 组件中,我在 map 函数中使用了一个函数。但是它返回一个错误
- css - 位置:粘性;在 Chrome mobile 79 下无法唤醒
- java - 如何从 QR/条形码将扫描数据插入 FireBase 实时数据库?
- sql - 试图从两列中获取数据并正确格式化它们
- android - 如何将活动移动到具有特定片段目标的另一个活动?
- scrapy - 屈服于 s3 存储桶时无法连接蜘蛛关闭
- azure-devops - 将多个现有工作项链接到排队生成(来自 Azure Devops SDK)
- django - Django:如何请求数据并同时使其可编辑