3D Least Squares Plane

后端 未结 9 2259
遥遥无期
遥遥无期 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条回答
  •  萌比男神i
    2020-11-27 14:40

    If you have n data points (x[i], y[i], z[i]), compute the 3x3 symmetric matrix A whose entries are:

    sum_i x[i]*x[i],    sum_i x[i]*y[i],    sum_i x[i]
    sum_i x[i]*y[i],    sum_i y[i]*y[i],    sum_i y[i]
    sum_i x[i],         sum_i y[i],         n
    

    Also compute the 3 element vector b:

    {sum_i x[i]*z[i],   sum_i y[i]*z[i],    sum_i z[i]}
    

    Then solve Ax = b for the given A and b. The three components of the solution vector are the coefficients to the least-square fit plane {a,b,c}.

    Note that this is the "ordinary least squares" fit, which is appropriate only when z is expected to be a linear function of x and y. If you are looking more generally for a "best fit plane" in 3-space, you may want to learn about "geometric" least squares.

    Note also that this will fail if your points are in a line, as your example points are.

提交回复
热议问题