【发布时间】:2021-06-15 07:59:35
【问题描述】:
我有大型点文件(点云?),其中包含 X、Y、Z 和第 4 个“值”列。从这些点云中,我想选择属于某个形状(例如圆柱体)的点并更改值。 我可以使用 .loc 并识别框区域中的点,但无法弄清楚如何为圆柱体(或其他任意形状)执行此操作。 在下面的示例中,我创建了一个小点云,然后选择由 X、Y、Z 限制定义的框内的点 - 我目前的需要是定义一个高度为10,半径为1的圆柱体(圆柱体应该沿着X轴,从-5开始,以X = 0为中心,Z = 3) 任何建议表示赞赏
import numpy as np# for array data processing
import pandas as pd
from matplotlib import pyplot as plt
X, Y, Z, V = np.mgrid[-10:10:10j, -2:2:10j, 0:5:10j, 1:1:10j]
data = np.array([X, Y, Z, V]).reshape(4, -1).T
points = pd.DataFrame(data, columns = ['X', 'Y', 'Z', 'Value'])
#boundaries of interest
Xl = 5
Yl = 1
Ztop = 4
Zbottom = 2
#in box
pointsneeded = points.loc[(points['X'] >= -Xl) & (points['X'] <= Xl) & (points['Y'] >= -Yl) & (points['Y'] <= Yl)
& (points['Z'] >= Zbottom) & (points['Z'] <= Ztop)]
#visualize
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
scat = ax.scatter(points['X'], points['Y'], points['Z'], c=points['Value'], alpha=0.1)
scat1 = ax.scatter(pointsneeded['X'], pointsneeded['Y'], pointsneeded['Z'], c='r', alpha=0.5)
plt.show()
【问题讨论】:
标签: python pandas point-clouds