Sign in to follow this  
SpaceDude

Fitting a plane to a 3d point set

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this