In 3D space I have some points (x
, y
and z
) and want to split them by reconstructing some exisiting planes. These are my simplified points:
points=[[np.array([[20., 20., 60.], [20., 30., 65.], [55., 30., 80.], [80., 10., 60.]]),\
np.array([[20., 10., 55.], [60., 30., 70.], [70., 15., 20.]])]]
The big list has one sublist which has two arrays. I reality points
has more subliststs and each sublist may also have several arrays. Then, In this simlified example I have two planes among the points. I have four corners of the two surfaces:
four_corners= [[np.array([[50., 5., 5.],
[50., 45., 5.],
[70., 45., 95.],
[70., 5., 95.]]),
np.array([[30., 5., 95.],
[30., 45., 95.],
[60., 5., 5.],
[60., 45., 5.]])]]
four_corners
has one sublist and this sublist has also two array, i.e. two surfaces. Then, each array of the first sublist of points
should be devided into three parts because two surfaces are passing through them. In case of having one plane, I will have two splits for each array. I want to split my point based on the surfaces. I tried to modify this solution but I could not reach what I want. I tried the following code but it was not successful:
splitted_arr=[]
for m in points:
for surfaces in four_corners:
for i, j in zip (m, surfaces):
j=np.array(j)
corners = [j[0], j[1], j[2]]
v1 = np.subtract(corners[1], corners[0])
v1 = v1 / np.linalg.norm(v1)
v2 = np.subtract(corners[-1], corners[0])
v2 = v2 / np.linalg.norm(v2)
orth = np.cross(v1, v2)
for p in i:
p_moved = np.subtract(p, corners[0])
d = np.dot(orth, p_moved)
if d < 0:
splitted_arr.append (p)
else:
splitted_arr.append (p)
I want to get:
[[np.array([[20., 20., 60.], [20., 30., 65.]]), np.array([[55., 30., 80.]]), np.array([[80., 10., 60.]]),\
np.array([[20., 10., 55.]]), np.array([[60., 30., 70.]]), np.array([[70., 15., 20.]])]]
The key rule is that I want to split my points always using existing planes. In advance, I do appreciate any help and contribution.