通过python定位给定距离的3D点

2024-06-16 10:08:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想根据三个基点之间的距离来定位一个三维点。 我试过spicy.optimize.fslove,但结果似乎并不令人满意

point1 = [0., 0., 0.]
point2 = [1., 0., 0.]
point3 = [0., 1., 0.]

def solveLocate(x):
    xp = float(x[0])
    yp = float(x[1])
    zp = float(x[2])

    return[
        (xp - point1[0]) ** 2 + (yp - point1[1]) ** 2 + (zp - point1[2]) ** 2,
        (xp - point2[0]) ** 2 + (yp - point2[1]) ** 2 + (zp - point2[2]) ** 2,
        (xp - point3[0]) ** 2 + (yp - point3[1]) ** 2 + (zp - point3[2]) ** 2,
    ]

result1=scipy.optimize.fsolve(solveLocate, [0.,1.,1.])
print result1
print solveLocate(result1)

我得到的答案是:

    /Library/Python/2.7/site-packages/scipy/optimize/minpack.py:161: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)

[ 0.38997015  0.38805274  0.00093549]
[0.30266251961577206, 0.5227222226668922, 0.5265570428112971]

所以我想问我怎样才能得到更有效和准确的解

谢谢


Tags: thescipyfloatzpxpoptimizeprint基点