【发布时间】:2021-03-23 11:32:40
【问题描述】:
我有两个 numpy 数组,它们都有一些点的坐标。一个数组具有切割平面的坐标 (cutting_surf),另一个数组具有一些点的坐标 (points):
cutting_surf=np.array([[3., 1., 3.], [2., 1., 1.],[3., 2., 3.],\
[2., 2., 1.], [3., 3., 3.], [2., 3., 1.]])
points=np.array([[1.2, 3., 3.], [4., 1., 2.], [2.2, 2., 1.], [1.2, 1.5, 3.], [2.5, 1.5, 3.],\
[2.9, 1., 3.], [2.9, 2., 2.9], [4., 3., 1.9], [3.2, 1.2, 3.], [2.2, 3., 3.5],\
[2.5, 3., 3.], [2.2, 1.5, 3.5]])
然后,我想从points 中删除一些多余的坐标。这些坐标太接近来自cutting_surf 的坐标。我使用了以下代码:
to_be_removed=points[np.where(np.min(distance.cdist(cutting_surf, points),axis=0)<0.5)[0],:]
cleaned_result= npi.difference(points, to_be_removed) # it removes that close points
在那之后,我的最终计划是将我的points 数组分成两个。事实上,我真的想用cutting_surf 切割points 数组。我的意思是我想让我的cleaned_result 成为:
[np.array([[2.5, 3., 3.],
[2.5, 1.5, 3.],
[1.2, 3., 3.],
[1.2, 1.5, 3.],
[2.2, 3., 3.5],
[2.2, 1.5, 3.5]])
np.array([[4. , 3. , 1.9],
[4. , 1. , 2. ]])]
我的图显示了我拥有的坐标分布。我在这里只展示了一些简单的坐标,并根据它们的x 值对它们进行排序,我可以将数组分成两个,但实际上它要复杂得多。我认为唯一的方法是使用cutting_surf 坐标创建表面,然后分离两个簇。我尝试使用cutting_surf 的四个角创建曲面,但我不知道如何使用此曲面对我的点进行聚类:
def plane_from_points(cutting_surf):
centroid = np.mean(cutting_surf, axis=0)
_, eigenvalues, eigenvectors = np.linalg.svd(cutting_surf - centroid)
if eigenvalues[1] < PRECISION:
raise ValueError("Points are aligned, can't define a plane")
normal = eigenvectors[2]
d = -np.dot(centroid, normal)
plane = np.append(normal, d)
thickness = eigenvalues[2]
return plane, thickness
在此先感谢您的帮助和贡献。
【问题讨论】:
-
我不确定我是否正确理解了这个问题,但这可能会有所帮助吗? stackoverflow.com/questions/1560492/…(显然,您必须在 3D 中使用平面而不是直线。)
-
亲爱的@Hans,感谢您向我发送链接。我的问题与此类似,但有点复杂,因为我是在 3D 和 Python 中进行的。