3D Least Squares Plane

后端 未结 9 2277
遥遥无期
遥遥无期 2020-11-27 13:56

What\'s the algorithm for computing a least squares plane in (x, y, z) space, given a set of 3D data points? In other words, if I had a bunch of points like (1, 2, 3), (4, 5

9条回答
  •  天涯浪人
    2020-11-27 14:39

    As with any least-squares approach, you proceed like this:

    Before you start coding

    1. Write down an equation for a plane in some parameterization, say 0 = ax + by + z + d in thee parameters (a, b, d).

    2. Find an expression D(\vec{v};a, b, d) for the distance from an arbitrary point \vec{v}.

    3. Write down the sum S = \sigma_i=0,n D^2(\vec{x}_i), and simplify until it is expressed in terms of simple sums of the components of v like \sigma v_x, \sigma v_y^2, \sigma v_x*v_z ...

    4. Write down the per parameter minimization expressions dS/dx_0 = 0, dS/dy_0 = 0 ... which gives you a set of three equations in three parameters and the sums from the previous step.

    5. Solve this set of equations for the parameters.

    (or for simple cases, just look up the form). Using a symbolic algebra package (like Mathematica) could make you life much easier.

    The coding

    • Write code to form the needed sums and find the parameters from the last set above.

    Alternatives

    Note that if you actually had only three points, you'd be better just finding the plane that goes through them.

    Also, if the analytic solution in unfeasible (not the case for a plane, but possible in general) you can do steps 1 and 2, and use a Monte Carlo minimizer on the sum in step 3.

提交回复
热议问题