【问题标题】:How to find coordinates of intercept point from a nearby point to a line in 3D?如何找到从附近点到 3D 线的截点坐标?
【发布时间】:2022-05-22 05:25:16
【问题描述】:

我在一条线上有两个点,比如 X1(x1,y1,z1) 和 X2(x2,y2,z2),我在这条线附近有一个外部点 X(x0,y0,z0)。我想编写一个 python 代码,它将返回我在 X1X2 线上的点 D(x,y,z) 的坐标,使得 XD 线垂直于 X1X2(投影)。这个问题与之前在here 讨论的问题很接近。我正在为 3D 坐标寻找 python 中的工作脚本。 谢谢

【问题讨论】:

标签: python


【解决方案1】:

感谢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

【讨论】:

    【解决方案2】:

    您可以使用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)
    

    【讨论】:

      猜你喜欢
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 2011-02-07
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多