![](/img/trans.png)
[英]To find 3D point on a line closest to another 3D point in Multi-view Geometry?
[英]How to find coordinates of intercept point from a nearby point to a line in 3D?
我在一条线上有两个点,比如 X1(x1,y1,z1) 和 X2(x2,y2,z2),我在这条线附近有一个外部点 X(x0,y0,z0)。 我想编写一个 python 代码,它将返回我在 X1X2 线上的点 D(x,y,z) 的坐标,使得 XD 线垂直于 X1X2(投影)。 这个问题与之前在这里讨论的问题很接近。 我正在为3D坐标寻找 Python 中的工作脚本。 谢谢
感谢MedAli的建议。 我最终得到以下解决方案:
""" Calculates coordinates of projection point of a P0
point on the line is the line(p1,p2) """
p = np.array(p0)
a = np.array(p1)
b = np.array(p2)
ap = p - a
ab = b - a
proPoint = a + np.dot(ap, ab)/np.dot(ab,ab) * ab
return proPoint
您可以使用scikit-spatial库。
有两个点,您可以通过以下方式定义线:
from skspatial.objects import Line, Point
point_x1 = Point([3, 6, 1])
point_x2 = Point([2, 1, 10])
line = Line.from_points(point_x1, point_x2)
然后在线上的投影点可以计算为:
point_x = Point([0, -1, -7])
point_xd = line.project_point(point_x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.