0

I wanna locate a 3D point, given the distance between three base point. I tried spicy.optimize.fslove, but it seems that the result is not satisfying.

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)

And I get the solve said:

    /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]

So I want to ask how I can get the solve more efficient and accurate.

Thanks!

KeyYD
  • 1
  • 1
  • Sorry what you are doing is unclear to me in `result1`: your trying to do square root ? or your are finding roots of non-linear function ? – Dadep Apr 13 '17 at 12:26
  • `fsolve` as the name suggests is a solver, it finds zeros. But your objective function has no zeros. If you want to minimise dedicated minimisers are more appropriate. Also note, that as it stands your function can be minimised component-wise (if your error metric is summed squares), so you can use a 1d minimser or even do it analytically. – Paul Panzer Apr 14 '17 at 00:49
  • `(xp - point1[0]) ** 2 + (yp - point1[1]) ** 2 + (zp - point1[2]) ** 2=0;``(xp - point2[0]) ** 2 + (yp - point2[1]) ** 2 + (zp - point2[2]) ** 2=1``(xp - point3[0]) ** 2 + (yp - point3[1]) ** 2 + (zp - point3[2]) ** 2=1`@Dadep – KeyYD Apr 15 '17 at 08:29
  • The equation should have a solve `[0.0, 0.0, 0.0]`@PaulPanzer – KeyYD Apr 15 '17 at 10:32
  • @KeyYD unless I'm mistaken, in the point `[0,0,0]` the function has value `[norm(point1)**2,norm(point2)**2,norm(point3)**2]` which is very much non-zero, so Paul is right. Also, your problem doesn't have a "given distance" from three points, only the three points. These suggest that you indeed need *minimization* rather than zero search. – Andras Deak -- Слава Україні Apr 16 '17 at 21:43
  • @AndrasDeak Good idea, thanks! – KeyYD May 13 '17 at 03:39

0 Answers0