【问题标题】:How to find the foot of a perpendicular given one point and a line with two points如何找到给定一个点和一条具有两点的线的垂线的脚
【发布时间】:2019-08-08 21:16:22
【问题描述】:

所有点都是3-d向量,假设一个点是a,有两个点(b和c)的线,现在画一条从a到线bc的垂直线,脚是,例如。 d、如何用numpy求d点的坐标?谢谢

假设:

a {x1, y1, z1}
b {x2, y2, z2}
c {x3, y3, z3}

我想交叉产品会有所帮助,但是,仍然不知道,请有人解释一下,谢谢!

# 3 points
def getfoot(a, b, c):
    foot = np.cross(a-b, b-c).... # no idea
    return root

d 要么在 bc 的内部,要么在 bc 的外部。

【问题讨论】:

  • 你不能只用公式从两点计算直线方程,然后用公式计算“英尺”吗?我认为这是一道数学题。
  • 这看起来很像家庭作业。
  • 我投票结束这个问题,因为它不是一个编程问题,而是一个数学问题
  • 数学已经算好了,你需要的就在这里:en.wikipedia.org/wiki/Vector_projection。除此之外你只需要知道numpy.vdot(a, b),这是向量点积。

标签: python numpy


【解决方案1】:

here得到答案

只是将a投影到ab线,不确定这是最简单的。

在这里发布我的代码。

def get_foot(p, a, b):
    ap = p - a
    ab = b - a
    result = a + np.dot(ap, ab)/np.dot(ab, ab) * ab
    return result

【讨论】:

  • 如果答案没有在链接之外增加价值,则答案将被否决。
猜你喜欢
  • 2017-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-28
  • 1970-01-01
  • 2016-03-24
  • 2013-01-18
相关资源
最近更新 更多