Fitting a plane to a 3d point set

Started by
5 comments, last by Eric Lengyel 19 years, 4 months ago
I have a set of points which are almost all in the same plane. How do I find the plane which best fits these points? I thought of a least squares method for planes. In theory it seems possible but I haven't found any websites that explain how to do it. I tried to derive it myself but got stuck very quickly. Any ideas? If not I will have to resort to taking cross-products of my points and averaging them.
Advertisement
This is once again a 15 second ad-hoc algo.. project your set to two orthogonal planes. Fit a line on both planes that best aproximates (in least squares sence) the point set. Now derive a plane equation from those lines (which are orthogonal to each other).
Google for "orthogonal distance regression". That should give you enough information.
Quote:Original post by Winograd
This is once again a 15 second ad-hoc algo.. project your set to two orthogonal planes. Fit a line on both planes that best aproximates (in least squares sence) the point set. Now derive a plane equation from those lines (which are orthogonal to each other).


That doesn't sound like a very good solution. It will fail if the plane that best fits the points is parallel to one of the arbitrary orthoganal planes chosen.

I did a search on "orthogonal distance regression", it didn't prove very usefull...

Any other ideas?
Found this thread
Quote:Original post by Winograd
Found this thread


Ok thanks that looks good, will take me a while to find out exactly how to implement this... I'm a little rusty on all the eigenvalue / eigenvector stuff.
You might want to check out principal component analysis. You can calculate a 3x3 covariance matrix for your set of points and then determine the eigenvectors corresponding to the two largest eigenvalues. These two vectors are parallel to the best-fit plane, so just cross them to get the plane's normal, and then adjust the plane's fourth coordinate so that it passed through the average position of your point set.

Principal component analysis is discussed in Section 7.1.1 of Mathematics for 3D Game Programming and Computer Graphics.

I've posted some code that will calculate that eigenvalues and eigenvectors of a 3x3 symmetric matrix (which includes the covariance matrix) here:

http://www.terathon.com/code/linear.html

(The CalculateEigensystem function is what you want.) The algorithm is described in Chapter 14 of the above book, as well as in Numerical Recipes in C.

-- Eric Lengyel

This topic is closed to new replies.

Advertisement