Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

python - how to find the coordinate of points projection on a planar surface

Hope doing well. I have two numpy array, both are some points in the space. Using python, I want to firstly find the surface passing the first data set (surface_maker) and then find the x,y and z of the projection adjacent opoints of the second array (contact_maker) on the created surface. surface_maker always created planar surfaces. For projection, I only want a vertical going from adjacent point toward the surface. In reality I have lots of points in both sets but I copies a simple case here:

surface_maker=np.array([[50., 15., 46.04750574],
                        [50., 5., 45.56400925],
                        [44.83018398, 5., 25.],
                        [44.76296902, 15., 25.],
                        [50., 25., 45.56400925],
                        [44.83018398, 25., 25.],
                        [59.8336792, 5., 75.],
                        [59.71483707, 15., 75.],
                        [59.8336792, 25., 75.]])
contact_maker=np.array([[10.,  5., 70.00014782],
                        [10., 15., 70.00018358],
                        [10., 25., 70.0001955 ],
                        [30.,  5., 69.99981105],
                        [30., 15., 69.99982297],
                        [30., 25., 69.99985874],
                        [70., 5., 50.00000298],
                        [70., 15., 50.00002682],
                        [70., 25., 50.00005066],
                        [90., 5., 49.99996871],
                        [90., 15., 49.99999255],
                        [90., 25., 50.00001788]])

I have tried several solutions like 1, 2 and so on. But I was successful to solve my issue. For me it is important to have the location of projection as x, y and z. The figure also shows what I want (as it shows, I need only location six adjacent point of the contact_maker projected on the surface created by surface_maker):

enter image description here

In advance, I truely appreciate any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We can build plane using any three non-collinear points from the first set.

Let points are A, B, C. At first calculate vectors

AB = B - A  (ab.x = b.x - a.x and so on)
AC = C - A

Now calculate normal vector using cross product

N = AB x AC

If N is zero vector, then points are collinear and we need to choose another triplet

(I'm sure that numpy contains ready-to-use functions for all these vector operations)

Now we have three components of the plane equation (normal components)

N.x * x +  N.y * y + N.z * z + D = 0

To get the fourth component D, just substitute A point into this equation

D = - (N.x * A.x +  Ny * A.y + Nz * A.z)

Seems that you projection is along OX axis. In this case for any point Q we can easily find projection onto plane solving

N.x * x +  N.y * Q.y + N.z * Q.z + D = 0
x = -(N.y * Q.y + N.z * Q.z + D) / N.x

for unknown x, whilst y and z coordinates of projection are equal to Q.y and Q.z

import numpy as np

S = np.array([[50., 15., 46.04750574], [50., 5., 45.56400925], [44.83018398, 5., 25.]])
AB = S[1] - S[0]
AC = S[2] - S[0]
N = np.cross(AB, AC)
D = - (N[0] * S[0][0] +  N[1] * S[0][1] + N[2] * S[0][2])
Q = np.array([10.,  5., 70.00014782])
x = -(N[1] * Q[1] + N[2] * Q[2] + D) / N[0]
print(x,Q[1],Q[2])

>>> 56.143273867965505 5.0 70.00014782

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...