# Fitting a plane to a set of points in 3D using PCA

I am trying to estimate a midplane of a 3D model using the midpoints of paired landmarks, in order to reconstruct missing data (midplane refers here to the middle/saggital plane of the cranium which cuts the skull into two symmetrical halves, left and right).

I therefore need to estimate a plane from 27 points in 3D. I need to get the equation of the plane as $$ax+by+cz=d.$$

I have looked into orthogonal regression and principal component analysis (PCA) as methods, however I didn't take maths past A-levels and am struggling. I know I can supposedly use the eigenvectors to get the equation of the plane of best fit, but need someone to explain exactly how. I am using R for the PCA but am not great at R either.

Alternatively, if there's a better way to estimate the plane I would be glad to hear it!

• what's a midplane? Jul 27, 2015 at 17:05
• Apologies, midplane is the middle plane of the cranium in this case, also known as the sagittal plane which cuts the skull into two symmetrical halves (left and right)
– Suzy
Jul 29, 2015 at 8:48
• sounds like machine learning is particularly well suited to this problem Jul 29, 2015 at 11:51
• The format of the output doesn't matter hugely, as long as I can work out the equation for the 3D plane in the following format: ax + by + cz = d. I have read about the first two eigenvectors being related and can run a PCA, however I don't understand what to do with the eigenvectors once I have obtained them, and how they can be used to work out the equation of the plane. Thanks in advance.
– Suzy
Aug 6, 2015 at 10:23
• Sorry for the delayed response @amoeba, this did answer my question and I have now tried out the method and gotten it to work! Many thanks!
– Suzy
Sep 2, 2015 at 11:57

When you perform principal component analysis (PCA) on your 27 points in 3D, you first subtract the mean vector $\mathbf m$ and then obtain three eigenvectors $\mathbf e_1, \mathbf e_2, \mathbf e_3$ of the covariance matrix. The first two eigenvectors (with two largest eigenvalues) span the plane that you want to find, so the geometric situation looks like that:
The question is: how to get from here to the equation of this plane in the form $$ax+by+cz=d.$$ This equation can be reformulated as follows: $\mathbf a \cdot \mathbf x = d$, where $\mathbf x$ is any point lying in the plane and $\mathbf a$ is a vector $(a,b,c)$. In other words, we need to find a vector $\mathbf a$ such that its dot product with any point in the plane gives the same constant value $d$.
From the picture above, we see that any point belonging to the plane can be written as $\mathbf x = \mathbf m+ g\mathbf e_1 + h\mathbf e_2$, where $g$ and $h$ are some real numbers. It follows that the dot product between $\mathbf e_3$ and $\mathbf x$ is given by $$\mathbf e_3 \cdot \mathbf x = \mathbf e_3 \cdot (\mathbf m+ g\mathbf e_1 + h\mathbf e_2) = \mathbf e_3 \cdot \mathbf m = \mathrm{const}.$$ So here we have it: we can take $\mathbf a = \mathbf e_3$ and $d = \mathbf e_3 \cdot \mathbf m$.