I have two numpy lists with 3D coordinates of vertecies of two meshes. These lists are of unequal length. I would like to calculate the 3D distance between every coordinate in arrayA and arrayB.
arrayA([[X1 , Y1 , Z1], [X2 , Y2 , Z2], [X3 , Y3 , Z3]]) ... arrayB([[X1 , Y1 , Z1], [X2 , Y2 , Z2], [X3 , Y3 , Z3], [X4 , Y4 , Z4]]) ... While searching I found this post about getting a single 3D coordinate pair distance but I am not sure how I can use it as my numpy arrays are of unequal lengths.
I would like to generate a numpy array with all the lengths. This means distances of All 3D coordinates from ArrayA with the first, second, third... (and so on) 3D coordinate of ArrayB.
---EDIT---
I feel like I have been able to make some progress but I think that something is still not right. I am experimenting with a subset of all the coordinates ant took the first 3 vertices from the two meshes. So ArrayA (vertex_array[0]) has 3 XYZ coordinates and ArrayB (vertex_array[1]) has 3 XYZ coordinates. I am expecting to get 9 output entries but it outputs 12. I have also put in a couple of print statements but I can't seem to figure it out.
import numpy as np ... iterate = 0 iterate2 = 0 ... for entries in vertex_array[1]: for vertex in vertex_array[0]: p1 = vertex p2 = vertex_array[1][0] iterate = iterate+1 squared_dist = np.sum((p1-p2)**2, axis=0) dist = np.sqrt(squared_dist) print(dist) print("loop 1: " + str(iterate)) p3 = vertex_array[0][0] p4 = entries iterate2 = iterate2 + 1 squared_dist2 = np.sum((p3-p4)**2, axis=0) dist2 = np.sqrt(squared_dist2) print(dist2) print("loop 2: " + str(iterate2)) Output:
3.677461821966065 loop 1: 1 3.36723045259329 loop 1: 2 3.7110807813512268 loop 1: 3 3.677461821966065 loop 2: 1 3.677461821966065 loop 1: 4 3.36723045259329 loop 1: 5 3.7110807813512268 loop 1: 6 4.029668579506317 loop 2: 2 3.677461821966065 loop 1: 7 3.36723045259329 loop 1: 8 3.7110807813512268 loop 1: 9 3.7166097270669267 loop 2: 3