【问题标题】:Select points within a cylinder from a 3D point cloud从 3D 点云中选择圆柱内的点
【发布时间】: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


    【解决方案1】:

    将圆柱体拆分为 2 个问题:(1) (x, y) 在圆内,(2) z 值在一定范围内

    例如对于点 p(x, y, z)

    def inside_circle(x, y, circle_radius):
      return sqrt(x*x+y*y) <= circle_radius:
    
    def between_range(z, min_z, max_z):
      return min_z <= z <= max_z
    
    radius, min_z, max_z = ...some number...
    points_to_keep = list()
    for x, y, z in your_dataset:
      if inside_circle(x,y) and between_range(z, min_z, max_z):
        points_to_keep.append([x,y,z])
    

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多