0

I have a 3D point cloud, I want fit a plane based on these points. And I want to know the normal vector of the fitting plane. Which algorithm is the best? Would you please give me detailed steps? I plan to write using R, any function I can use?

Tao
  • 1
  • 1
  • 1

1 Answers1

2

The equation for a plane in three dimensions is Ax + By + Cz + D = 0. Hence, the best fitting plane will be the one where A, B, C, and D are chosen such that when you plug in the 3-D coordinates into the formula, the result is as close to zero as possible. Said another way, you're looking for the best vector v that satisfies the matrix equation Mv = 0, where M is a matrix representing your data points:

     | x1  y1  z1  1 |        |  A  |    Need to solve:
     | x2  y2  z2  1 |        |  B  |       Mv = 0
 M = | x3  y3  z3  1 |    v = |  C  |
     |   .  .  .     |        |  D  |
     | xn  yn  zn  1 |

I'm not familiar with R, but a quick google search says that the lsfit function should do what you need. Once you compute the coefficients A-D, the vector (A, B, C) will be the normal vector and the scalar D will be the distance the plane is from the origin.

Mokosha
  • 2,737
  • 16
  • 33
  • 1
    You also need to add some extra condition (e.g. A²+B²+C²=1) as obviously A=B=C=D=0 is always an exact solution. – 6502 Jul 23 '16 at 14:42