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

时间:2017-04-13 12:08:20

标签: python scipy nonlinear-functions equations

我想找到一个3D点,给定三个基点之间的距离。 我试过了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]

所以我想问一下如何才能更有效,更准确地解决问题。

谢谢!

0 个答案:

没有答案