Fit a plane to a set of xyz points

Just one quick note on this:

If you fit Z = aX + bY + c, you won’t be able to resolve vertical planes. Likewise, if you fit x = aY + Bz + c or y = aX + bZ + c you won’t be able to resolve horizontal planes.

If you need to robustly fit a plane to a point cloud, you’ll need to try all three formulations. See here for a quick example of what Friedrich mentioned using all three formulations and choosing the most robust result:

As far as finding the distance of a given point (x0, y0, z0) to the plane defined by “0 = ax + by + cz + d”, the equation is just abs(a * x0 + b * y0 + c * z0 + d) / sqrt(a2 + b2 + c**2). See here for a more detailed explanation.



On Tue, Jul 27, 2010 at 1:37 PM, Friedrich Romstedt <friedrichromstedt@…287…> wrote:

2010/7/26 Mathew Yeates <mat.yeates@…287…>:

Is there a simple function call for this? And finding the distance of

a point to the plane?

Hmm, when you are interested in the z distance alone, it should be a

matrix equation:

Z = X * m_x + Y * m_y + 1 * n

Meaning you can invert it with Moore-Penrose pseudoinversion, i.e.,


When you have weights on Z, normalise first.