Issue
Inspired by the answer here, I would like to calculate the perpendicular distance (in vector format instead of just magnitude) from a point to a straight line in 3D space.
The above mentioned equation does give the magnitude.
import numpy as np
norm = np.linalg.norm
p1 = np.array([0,0,0])
p2 = np.array([10,0,3])
p3 = np.array([6, -3, 5])
ppDist = np.abs(norm(np.cross(p2-p1, p1-p3)))/norm(p2-p1)
print(ppDist) # 4.28888043816146
ppDist
vector in reality would be (0.8807339448,3,-2.935779817)
such that its norm()
is 4.288880438
Here's a quick visualization -
Solution
Find projection of P13 vector on P12 and the vector difference of P13 from the projection would be the perpendicular vector.
P12 = p2-p1
P13 = p3-p1
proj_13over12 = np.dot(P13, P12)*P12/norm(P12)**2 # array([6.88073394, 0. , 2.06422018])
perpendicular = proj_13over12 - P13
print(perpendicular) # [ 0.88073394 3. -2.93577982]
Answered By - beta green
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.