Given a set of points in 3D, the general problem is to find the a, b, c
coefficients of a plane equation in the form:
z = a*x + b*y + c
such that the resulting plane is the best fit possible to that set of points.
In this SO answer, the function scipy.optimize.minimize is used to solve this problem.
It relies on initial guesses for the coefficients, and minimizes an error function that sums the distances of each point to the surface of the plane.
In this code (based on this other SO answer) the scipy.linalg.lstsq function is used to tackle the same problem (when restricted to a 1st order polynomial).
It solves for
C
in the equationz = A*C
, whereA
is the concatenation of thex,y
coordinates of the set of points,z
is thez
coordinate of the set, andC
are thea,b,c
coefficients.Unlike the code in the method above, this one does not seem to require initial guesses for the plane coefficients.
Since the minimize
function requires an initial guess, this means that it may or may not converge to the optimal solution (depending on how good the guess is). Does the second method have a similar caveat or will it return an always exact solution?