I have some kind of a complicated geometrical question.
I have two series of points represented by their x,y and z as numpy arrays (in reality I have thousands in each series but make it here simple for a better understanding).
First data set (arr_1
) represents a cutting surface. This surface is usually vertical and displaces horizontal surfaces. The second set is points of the vertical surfaces that are displaces by a surface (the surface that arr_1
is representing). At the moment I have some redundant data in these two sets. Firstly, in arr_1
I prefer to have only four corners points and make a surface by myself using them. Secondly, in arr_2
I also do not need the data that are too close to arr_1
. Finally, I want to terminate the points excising in both sides of the surface which is made by four corners of the arr_1
.
import numpy as np
arr_1= np.array ([[31.95548952, 7.5 , 12.5 ],
[31.95548952, 22.5 , 12.5 ],
[37.5 , 7.5 , 24.20636043],
[37.5 , 22.5 , 24.20636043],
[43.78154278, 7.5 , 37.5 ],
[43.78154278, 22.5 , 37.5 ],
[55.32209575, 7.5 , 62.5 ],
[55.32209575, 22.5 , 62.5 ],
[62.5 , 7.5 , 78.50696445],
[62.5 , 22.5 , 78.50696445],
[66.52446985, 7.5 , 87.5 ],
[66.52446985, 22.5 , 87.5 ]])
arr_2= np.array([[87.5 , 7.5 , 49.99997914],
[87.5 , 22.5 , 50.00001192],
[62.5 , 7.5 , 50.00004172],
[62.5 , 22.5 , 50.00007749],
[46.8747884 , 7.5 , 62.5 ],
[46.87483609, 22.5 , 62.5 ],
[37.5 , 7.5 , 69.99973059],
[37.5 , 22.5 , 69.99977231],
[12.5 , 7.5 , 70.00012398],
[12.5 , 22.5 , 70.00015974]])
Then, I find the distances between each set of these two arrays using the following code:
from scipy.spatial import distance
distances=distance.cdist(arr_1, arr_2)
When I run it, distances
is an array with 12 rows and 10 columns.
Now, I want to remove the points of arr_2
which closer than a threshold (let's say 10) to any point of arr_1
. I showed these two points in a black rectangle in the first uploaded photo. A good solution is proposed here, but it does not solve my problem because I want to compare the distance of each row of arr_1
with each row of arr_2
. I appreciate any solution to do it.
In fact, arr_1
contains the points of a surface but I do not need all of them to make my surface. I only pick for corners of this set to make my surface. I use a highly time consuming for loop, so I appreciate any faster method to find corners of my points:
corner1 = np.array(arr_1.min (axis=0)) # this gives the row containing MIN values of x,y and z
corner2 = np.array([])
corner4 = np.array([])
corner3 = np.array(arr_1.max (axis=0)) # this gives the row containing MAX values of x,y and z
# the next block will find the corner in which x and y are minimum and z is maximum
for i in arr_1[:,0]:
if i == max (arr_1[:,0]):
for j in arr_1[:,1]:
if j == min (arr_1[:,1]):
for h in arr_1[:,2]:
if h == max (arr_1[:,2]):
corner2 = np.append(corner2, np.array([i,j,h]))
corner2=corner2[0:3]
# the next block will find the corner in which x and z are minimum and y is maximum
for m in arr_1[:,0]:
if m == min (arr_1[:,0]):
for n in arr_1[:,1]:
if n == max (arr_1[:,1]):
for o in arr_1[:,2]:
if o == min (arr_1[:,2]):
corner4 = np.append(corner4, np.array([m,n,o]))
corner4=corner4[0:3]
Finally, after extracting four corners, I want to make a surface using them, and find the perpendicular (green arrows) or horizonal (red arrows) projection of adjacent points of arr_2 on it. I have no idea idea how to find the surface and projections.
Thanks for reading and payying attention to my detailed issue! I appreciate if anyone propose any solution to any part of it.