# Fitting a plane to a 3d point set

This topic is 5070 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
Google for "orthogonal distance regression". That should give you enough information.

##### Share on other sites
Quote:
 Original post by WinogradThis 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 on other sites
Quote:

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.

##### 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

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632983
• Total Posts
3009706
• ### Who's Online (See full list)

There are no registered users currently online

×