I have the following set of 4 Cartesian coordinates:
coords = [3.64811 7.61531 9.05108; 3.53604 4.82801 9.05108; 3.53604 4.82801 6.34192; 3.64811 7.61531 6.34192]
I am trying to fit a plane of the form $ax+by+c=z$ to these 4 coordinates. I tried both the analytical least-squares solution, as described here, and an iterative approach described here. These both result in relatively high root-mean-square-errors but I am not sure why. Using the curve fitting toolbox in MATLAB results in an $r^2$ that's negative and notes that the equation is badly conditioned, although visually the resulting fit looks okay somehow (image below).
It is rather intuitive what the plane should be. What can I do to get a more accurate solution? Mathematically, what is the issue with this set of coordinates?
However, in your case, there does in fact exist a plane that contains all four points (additionally, your four points are the vertices of a rectangle that is not a square, but this is not directly relevant).
– Zubin Mukerjee Dec 23 '17 at 04:55pinv(A'*A)*A'*B
to get a column vector with $a$, $b$, and $c$, whereA = horzcat(coords(:,1),coords(:,2),ones(4,1))
andB=coords(:,3)
– Argon Dec 23 '17 at 05:05