我在多維點雲數據文件中存儲了數百萬個xyz座標,這些文件存儲在二維numpy數組中:[[x1, y1, z1], [x2, y2, z2],..., [xn, yn, zn]]
。在numpy邊界框內查找點
我想過濾由4個座標[[x1, y1], [x2, y2]]
描述的特定邊界框內的所有點,即矩形的左下角和右上角座標。
我已經找到了下面一段代碼來過濾numpy的座標,它幾乎是我想要的。唯一的區別是(如果我正確的話)我的二維數組也有z座標。
import random
import numpy as np
points = [(random.random(), random.random()) for i in range(100)]
bx1, bx2 = sorted([random.random(), random.random()])
by1, by2 = sorted([random.random(), random.random()])
pts = np.array(points)
ll = np.array([bx1, by1]) # lower-left
ur = np.array([bx2, by2]) # upper-right
inidx = np.all(np.logical_and(ll <= pts, pts <= ur), axis=1)
inbox = pts[inidx]
outbox = pts[np.logical_not(inidx)]
我怎麼會得modifiy上面的代碼,使其與XYZ座標的工作由兩個x,y座標描述的邊框來過濾?
但像這樣我就失去了Z-信息,或沒有?我肯定需要保留這些以備後續計算。 – conste
@conste您將使用原始的3D「pts」來構建「收件箱」。 – DyZ