MATLAB: Selecting points which belong to parallel planes

planesprincipal axis

Hi and thanks for looking
I have a cloud of points, which very roughly form an irregular cylinder. I need to draw a number of parallel planes through it and calculate which points belong to which plane. Then, I need to calculate the squared sum of distances from those points to the principal axis. So, for each plane there will be 1 value (sq sum of distances). I have calculated its principal axis and am not sure how to proceed next. I know that the principal axis is the normal to the planes
Thank you for your help

Best Answer

It's a matter of simple vector analysis. Let P0 = [x0,y0,z0] be some base point on your principal axis and let n = [nx,ny,nz] be a vector pointing along this axis from P0. Now let P1 = [x1,y1,z1] be some point in your cloud. You wish to find the point P2 = [x2,y2,z2] at which the principal axis intersects the plane which is orthogonal to the axis and contains P1, and you want to find the squared distance between P1 and P2. Then we know that
1) P2-P1 is orthogonal to n
and
2) P2-P0 is equal to some scalar multiple of n
Combining these two facts we can arrive at a solution for P2:
P2 = P0 + dot(P1-P0,n)/dot(n,n)*n;
Then the squared distance between P1 and P2 would be dot(P1-P2,P1-P2).
I should add that it is easy to vectorize the expressions for all the P2 points and the squared distances, making use of the bsxfun function.