3

I am trying to find a plane in 3D space that best fits a number of points. I want to do this using SVD. To calculate the SVD:

  1. Subtract the centroid of the points from each point.
  2. Put the points in an mx3 matrix.
  3. Calculate the SVD (e.g. [U, S, V] = SVD(A)).

The last column of V, (e.g. V(:,3)), is supposed to be a normal vector to the plane. While the other two columns of V (e.g. V(:,1) and V(:,2)) are vectors parallel to the plane (and orthogonal to each other). I want to find the equation of the plane in ax+by+cz+d=0 form. The last column of V (e.g. V(:,3)) gives "a", "b", and "c", however, in order to find "d", I need a point on the plane to plug in and solve for d. The problem is that I don't know what are valid points to use to plug in.

My question is: does the centroid of the points necessarily lie on the fitted plane? If so, then it's easy to just plug in the centroid values in the equation (along with the from the norm) and solve for "d". Otherwise, how can I calculate "d" in the above equation? The matrix U apparently gives the point values but I don't understand which values to take.

Image showing a plane being fit to a set of points. Points "above" the plane after it is fit are blue and points "under" the plane after it is fit are purple.  The red point shows a point that is incident to the fitted plane and the green point shows the approximate centroid.

  • 1
    There's a short proof of this in the paper Principal Axes and Best-Fit Planes, with Applications by Christopher Brown, see e.g. https://urresearch.rochester.edu/fileDownloadForInstitutionalItem.action?itemId=13451&itemFileId=31154 (Proposition 1). – Ailurus Jun 20 '21 at 20:01
  • @Ailurus Thanks! The paper you listed has a very useful & straightforward answer...I don't understand why it's not out there more. I formatted the text/equations and added it as an answer. – user70891 Jun 22 '21 at 00:18
  • 1
    Glad the reference was useful! Indeed, the author's proof of Proposition 1 is easy to follow. The proof of Proposition 2 feels a bit artificial to me, though at the same time it has a certain elegance to it. For more details on this aspect, see e.g. the answers to this question on Math.SE – Ailurus Jun 22 '21 at 19:58
  • I started going through Proposition 2 and didn't grasp it immediately. I didn't need it (since Proposition 1 answered my question) so I kind of stopped there but I have it on my "things to check if I ever get the chance" list. I will look at the link you gave. Hopefully this will make it easier to follow/confirm Proposition 2. – user70891 Jun 23 '21 at 00:55

2 Answers2

3

Suggested by @Ailurus (thanks!!!)

Excerpted from: PRINCIPAL AXES AND BEST-FIT PLANES, WITH APPLICATIONS, by Christopher M. Brown, University of Rochester.

Consider the problem of finding a plane which “best fits” a swarm of weighted points. If the points are in n-space, the plane is a hyperplane; we will refer to it as a plane. Represent k-weighted points in n-space by row n-vectors x$_{\mathrm{i}}$, i=1, 2, ..., k; let the weight of the ith point be w$_{\mathrm{i}}$. Represent an n-1-dimensional subspace Π of n-space (a hyperplane) by a unit n-vector $\vec {\boldsymbol{z}}$ normal to Π and a point $\vec {\boldsymbol{v}}$ in Π. In the "sequel" (the following equations), all summations run from 1 to k.

The signed perpendicular distance from x$_{\mathrm{i}}$ to the plane (Π) is: \begin{equation*} \mathrm{d}_{\mathrm{i}Π }=\left(\vec {\boldsymbol{x}}_{i}-\vec {\boldsymbol{v}}\right)\cdot \vec {\boldsymbol{z}}. \end{equation*}

The error measure we wish to minimize is the sum over all points of the square of this distance times the weight (mass) of the point, i.e. \begin{equation*} \begin{array}{c} e=\sum _{i}\left(\left(\vec {\boldsymbol{x}}_{i}-\vec {\boldsymbol{v}}\right)\cdot \vec {\boldsymbol{z}}\right)^{2}w_{i}=\sum _{i}\vec {\boldsymbol{z}}\left(\vec {\boldsymbol{x}}_{i}-\vec {\boldsymbol{v}}\right)^{T}\left(\vec {\boldsymbol{x}}_{i}-\vec {\boldsymbol{v}}\right)\vec {\boldsymbol{z}}^{T}w_{i}=\vec {\boldsymbol{z}}\boldsymbol{M}\vec {\boldsymbol{z}}^{T}. \left(1\right) \end{array} \end{equation*} The equation (1), ${\boldsymbol{M}}$ is a real, symmetric n x n matrix, sometimes called the "scatter matrix" of the points. \begin{equation*} \begin{array}{c} \boldsymbol{M}=\sum _{i}w_{i}\left(\vec {\boldsymbol{x}}_{i}-\vec {\boldsymbol{v}}\right)^{T}\left(\vec {\boldsymbol{x}}_{i}-\vec {\boldsymbol{v}}\right). \left(2\right) \end{array} \end{equation*} First, we show that the best-fit plane passes through the center of mass (C. of M.) of the points. (The answer to the original question.)

$\underline{Proposition 1}.$ For ${e}$ of equation (1) to be minimized, the plane must pass through the C. of M. of the point swarm. Thus, in equation (1), ${e}$ may attain a minimum when $\vec {\boldsymbol{v}}$ is the C. of M.

$\underline{Proof}$: \begin{equation*} e=\sum _{i}w_{i}\vec {\boldsymbol{z}}\left(\vec {\boldsymbol{x}}_{i}\cdot \vec {\boldsymbol{x}}_{i}\right)\vec {\boldsymbol{z}}^{T}-2\sum _{i}w_{i}\vec {\boldsymbol{z}}\left(\vec {\boldsymbol{x}}_{i}\cdot \vec {\boldsymbol{v}}\right)\vec {\boldsymbol{z}}^{T}+\sum _{i}w_{i}\vec {\boldsymbol{z}}\left(\vec {\boldsymbol{v}}\cdot \vec {\boldsymbol{v}}\right)\vec {\boldsymbol{z}}^{T}. \end{equation*} Since $\vec {\boldsymbol{z}}\vec {\boldsymbol{z}}^{T}=1$ by definition, \begin{equation*} \frac{\partial e}{\partial \vec {\boldsymbol{v}}}=-2\sum _{i}w_{i}\vec {\boldsymbol{x}}_{i}+2\vec {\boldsymbol{v}}\sum _{i}w_{i}; \end{equation*} Setting $\frac{\partial e}{\partial \vec {\boldsymbol{v}}}=0$ implies \begin{equation*} \vec {\boldsymbol{v}}=\frac{\sum _{i}w_{i}\vec {\boldsymbol{x}}_{i}}{\sum _{i}w_{i}}, \end{equation*} which is the center of mass.

So, it is possible to find a point in the best-fit plane; the plane would be determined completely if a normal vector for it could be obtained. (The original paper explains how to do this in the subsequent propositions/proofs.)

  • @Bradley Bauer Thanks for catching that. I copied the original author's text word for word, including his (transcription) mistake. I should have checked the math more thoroughly as you did. My bad. Thanks again! – user70891 Feb 20 '23 at 09:42
0

Let $c$ denote the centroid of the points $x_1, x_2,\ldots x_n$.

In the first step, you translated the centroid $c$ to the origin, and obtained new points $x_i'=x_i-c$. If you do not believe me that the origin is the centroid of $x'_i$, then you should just compute it yourself to see.

In the last step the plane normal to your vector contains the origin. The normal plane, call it $P'$, is the best fit through $x'_1,\ldots, x'_n$, and it contains the origin, since it is defined as the plane perpendicular to a vector, and every such plane contains the origin.

Now, translating everything by a vector is an isometry. This is true both for $x\mapsto x-c$ and $x\mapsto x+c$. They preserve all distances, and therefore preserve all the nice properties of a plane fitted to points.

Since $P'$ you find in step 3 is optimally fitted to the translated points, we may use the inverse translation by translating everything back with $x\mapsto x+c$ to find the best fit for the original points. Every point $p$ on the plane from step 3 goes to $p+c$. This produces a new plane $P$ which fits the original $x_1,x_2,\ldots x_n$.

Since the centroid (the origin, $(0,0,0)$) of $x'_1, \ldots, x'_n$ was on the unshifted plane, the shifted origin $(0,0,0)+c=c$ is on the fitted plane of the original points.

rschwieb
  • 160,592
  • The centroid gets translated to the origin and the plane gets fitted to the points centered about the translated centroid. Will the fitted plane necessarily go through the origin? Intuitively it would but is there a way to prove that? – user70891 Feb 05 '20 at 19:35
  • The normal hyperplane to any vector contains the origin. The origin is orthogonal to everything. Is that what you are asking? – rschwieb Feb 05 '20 at 19:38
  • In general terms, a plane in 3D space needs 3 unique points to describe the plane. If you have more than 3 points then there is an over-fitting problem. To resolve the over-fitting problem and to best fit the plane to all the points, we use SVD to minimize the error of the normal distance from "all" possible planes to all the points. The plane that gives the minimum error "wins" as the plane that gives the best fit. To fit the points, all the points get translated about the origin, with the centroid getting translated directly to the origin. The SVD gets calculated based on the translated pts. – user70891 Feb 08 '20 at 04:53
  • The above skips a lot but that's the general idea. My question is whether or not the generated best-fit plane will necessarily go through the origin/centroid. As you mention, the origin is orthogonal to everything. However what is not clear to me is that while the origin/centroid is used as part of the calculations in the SVD, is the centroid necessarily in/on the best-fit plane? For example, if I were trying to fit a paraboloid using the same basic method, first shifting all the points around the origin/centroid, would the centroid be on the surface of the best-fit paraboloid? – user70891 Feb 08 '20 at 05:04
  • @user70891 Do you agree that the normal plane to the shifted data is the best fit for the shifted data? And that the origin is in the normal plane? – rschwieb Feb 08 '20 at 13:59
  • Intuitively, it would seem that the normal plane to the shifted data is the best fit for the shifted data. However, isn't there some error involved...or does SVD give an exact/"perfect" solution? Regarding whether the origin is in the normal plane, that is my main question--I don't know if the origin is in the normal plane. I assume it is "close" to the normal plane but if the best fit plane has some error associated with it, then does the error cause the plane to be offset from the origin? Or regardless of any error, will the best fit plane always go through the origin? – user70891 Feb 08 '20 at 21:58
  • @user70891 The normal plane to a vector in 3 space is the set of all vectors with dot product zero to that vector. The zero vector has dot product zero with every vector. Ergo the origin is in every normal plane. There is nothing complicated with what I’m saying. – rschwieb Feb 09 '20 at 01:08
  • @user70891 Yes, there is some error, but SVD is optimal in the sense that it minimizes error (with respect to a certain error estimate.). Translation is an isometry, so the shifted points for the plane as well as the shifted plane fits the original points. – rschwieb Feb 09 '20 at 01:09
  • The fitted plane will always be orthogonal to the origin/centroid but that does not necessarily mean it has to be coincident with the origin/centroid. Yes, we can translate the plane so that it is coincident, but my question is whether the best fit plane is necessarily coincident with the centroid or not (regardless whether the centroid and points are translated to/about the origin). – user70891 Feb 10 '20 at 05:36
  • @user70891 The normal plane will be orthogonal to the last column of $V$, not necessarily the position vector of the centroid. The normal plane defined by any vector necessarily contains (if "coincident" is supposed to mean something else you'll have to let me know) the origin. Of course you need to translate the plane, because the plane computed passes through the origin, and can be very far away from the unshifted points. It fits the shifted points. Translating it back with the original centroid causes it to fit the original points and causes it to contain the centroid. – rschwieb Feb 10 '20 at 11:53
  • I have added an image that shows a plane that is "best-fit" to a set of points. The green point shows the approximate centroid and the red point shows a point that is "coincident" with the plane. When I say "coincident", I mean the point lies on/in the plane. Are you saying that the centroid (point) doesn't necessarily lie on the fitted plane? – user70891 Feb 10 '20 at 20:50
  • @user70891 I have explained several times the centroid lies on the fitted plane. I have expanded my answer to be as elementary as possible. If you still have questions about what I've written, please ask something specific. I count you have asked your questions four more times in the comments above, and I get the feeling you are simply ignoring the reasons I'm giving. If you ask a fifth time, I simply won't respond anymore, because it does not look like you are asking in good faith. Have a good evening. – rschwieb Feb 11 '20 at 01:20
  • Thank you for taking the time to write comments. Yes, I've asked the same question multiple times and you've answered differently each time. If nothing else, it proves my sanity (thank you). You said, "...that does not necessarily mean it has to be coincident with the origin/centroid. " however in your last message you said, "the centroid lies on the fitted plane" those two answers are incongruous. – user70891 Feb 11 '20 at 22:41
  • Yes, the centroid is shifted to the origin and I understand the shifting of the other points and the plane after doing the SVD, etc. In your edited answer, you say, "In the last step the plane normal to your vector contains the origin. " That is where I am confused and that is my question. The centroid will absolutely be at the origin, I agree wholeheartedly, but does the SVD guarantee that the centroid will lie on the fitted plane? Somehow I don't see that mathematical proof in your answer(s). – user70891 Feb 11 '20 at 22:56
  • To address the first comment: I have said the same thing four times: i have not wavered at all. The phrase "that does not necessarily mean it has to be coincident with the origin/centroid" is a quote of yours not mine. – rschwieb Feb 12 '20 at 02:40
  • To address the second comment: yes thank you for a clear question. Look, suppose $(a,b,c)$ is the normal vector you find in the last step. Do you agree that its dot product with the origin $(0,0,0)$ is zero? – rschwieb Feb 12 '20 at 02:40
  • I think I deleted my answer instead of submitting it. Lovely. I'm resending now. When you say "dot product with the origin" do you mean dot product with the zero vector? If that's the case, yes the dot product is 0. If it's a dot product with a vector that goes through the origin then in most cases, no, in some cases, like when the vectors are orthogonal to the plane's vector, yes. – user70891 Feb 19 '20 at 22:34
  • @user70891 The plane normal to a vector is the set of vectors which have dot product zero to the normal vector. And the origin is one of those. Hence the origin is in the normal plane. I can't make this any more obvious than it already is. – rschwieb Feb 19 '20 at 22:39
  • The origin is a point. Not a vector. Any plane will have a vector perpendicular to it which can go through the origin. That doesn't mean the origin lies in the plane. – user70891 Feb 19 '20 at 22:45
  • Here is an example, ax + by + cz = d is the equation of a plane. <a,b,c> is the normal vector and d is the normal distance from the origin to the plane. In this case, <a,b,c> dotted with your "origin" would be 0. However the origin does not lie on the plane. – user70891 Feb 19 '20 at 22:50
  • @user70891 You are confusing several things together. The first thing is: any vector $(a,b,c)$ in $\mathbb R^3$ uniquely defines a plane (a two-dimensional subspace of $\mathbb R^3$ through the origin by the relation $(a,b,c)\cdot (x,y,z)=0$. Notice this matches your equation when $d=0$. Now, geometrically, a normal to this plane will be normal to all its translations, and so one could say $(a,b,c)$ is normal to all of them, but it isn't algebraically normal to them (the dot product is not zero with points lying on them.) I am talking about 2-dimensional subspaces of $\mathbb R^3$. – rschwieb Feb 19 '20 at 23:07
  • Here's what that can be confused with: you can define a translated plane as (algebraically) normal points of $\mathbb R^4$ using projective coordinates. However, I saw no indication you were doing this: as far as I can tell you're talking about vectors of $\mathbb R^3$. If you'd like to clarify what the dimensions of $S,V$ and $D$ are, maybe you would like me to rephrase this. – rschwieb Feb 19 '20 at 23:10
  • "the origin is not a point, not a vector" is a wrongheaded statement. Points in $\mathbb R^n$ are identified with vectors in $\mathbb R^n$, namely their position vectors. The vector $(0,0,0)$ is just the position vector of the origin. – rschwieb Feb 19 '20 at 23:11