[英]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.