我如何找到一条线的方程通过2点并通过线-python传递点

时间:2018-01-10 06:37:39

标签: python arrays algorithm numpy jupyter-notebook

我有两点:

(283,240,302)
(150,150, 50)

我想知道两点的方程,我想找(x,y,z) 距离点(150,150,50)的距离R

enter image description here

1 个答案:

答案 0 :(得分:0)

最简单的方法是使用向量:计算AB向量,并使用比例来计算AC向量。然后从AC计算C位置:

A = (150, 150, 50)
B = (283, 240, 302)

from math import sqrt

AB = [A[i] - B[i] for i in range(3)]
length_AB = sqrt(sum([u*u for u in AB]))
AC = [u*600/length_AB for u in AB]

C = [AC[i]+A[i] for i in range(3)]