I have two numpy arrays both having coordinates of some points. One array has the coordinates of a cutting planar surface (cutting_surf
) and another one has coordinates of some points (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]])
Then, I want to remove some redundant coordinates from points
. These coordinates are too close to the coordinates from cutting_surf
. I used the following code to do so:
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
After that, my final plan is to divid my points
array into two ones. In fact, I want to really cut points
array using cutting_surf
. I mean I want to get my cleaned_result
as:
[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. ]])]
My fig shows the distribution of coordinates that I have. I presented just some simple coordinates here and by sorting them based on their x
values I can divide the array into two one but in reality it is much more complicates. I think the only way is creating the surface using cutting_surf
coordinates and then separating two clusters. I tried creating the surface using four corners of cutting_surf
but I have no idea how to cluster my points using this surface:
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
In advance, I appreciate any help and contribution.