How can i measure the distance between each point of my 3D points-cloud and the mean plan?

42 views (last 30 days)
Ubaldo Pantaleo
Ubaldo Pantaleo on 12 Mar 2015
Edited: Bruno Luong on 18 Oct 2018
I have a 3D pointcloud. Each point has its xyz local coordinates. I found the mean plan indentified by the 3D pointcloud. I need to measure the perpendicular distance between points and mean plan.
I'm doing in this way but, i think, i'm not measuring the PERPENDICULAR distance from the mean plan.
%% Loading data %data = load('Coralligeno_outcrop.txt'); data = load('./input.dat'); x = data(:,1); y = data(:,2); z = data(:,3); clear data;
%% Plotting Surface figure(100) scatter(x,y,2,z) %mean(z) %std(z)
%% Finds the mean plan % Combine X,Y,Z into one array XYZ = [x,y,z];
% column means. This will allow us to do the fit properly with no % constant term needed. It is necessary to do it this way, as % otherwise the fit would not be properly scale independent cm = mean(XYZ,1);
% subtract off the column means XYZ0 = bsxfun(@minus,XYZ,cm);
% The "regression" as a planar fit is now accomplished by SVD. % This presumes errors in all three variables. In fact, it makes % presumptions that the noise variance is the same for all the % variables. Be very careful, as this fact is built into the model. % If your goal is merely to fit z(x,y), where x and y were known % and only z had errors in it, then this is the wrong way % to do the fit. [U,S,V] = svd(XYZ0,0);
% The singular values are ordered in decreasing order for svd. % The vector corresponding to the zero singular value tells us % the direction of the normal vector to the plane. Note that if % your data actually fell on a straight line, this will be a problem % as then there are two vectors normal to your data, so no plane fit. % LOOK at the values on the diagonal of S. If the last one is NOT % essentially small compared to the others, then you have a problem % here. (If it is numerically zero, then the points fell exactly in % a plane, with no noise.) diag(S)
% Assuming that S(3,3) was small compared to S(1,1), AND that S(2,2) % is significantly larger than S(3,3), then we are ok to proceed. % See that if the second and third singular values are roughly equal, % this would indicate a points on a line, not a plane. % You do need to check these numbers, as they will be indicative of a % potential problem. % Finally, the magnitude of S(3,3) would be a measure of the noise % in your regression. It is a measure of the deviations from your % fitted plane.
% The normal vector is given by the third singular vector, so the % third (well, last in general) column of V. I'll call the normal % vector P to be consistent with the question notation. P = V(:,3);
% The equation of the plane for ANY point on the plane [x,y,z] % is given by % % dot(P,[x,y,z] - cm) == 0 % % Essentially this means we subtract off the column mean from our % point, and then take the dot product with the normal vector. That % must yield zero for a point on the plane. We can also think of it % in a different way, that if a point were to lie OFF the plane, % then this dot product would see some projection along the normal % vector. % % So if your goal is now to predict Z, as a function of X and Y, % we simply expand that dot product. % % dot(P,[x,y,z]) - dot(P,cm) = 0 % % P(1)*X + P(2)*Y + P(3)*Z - dot(P,cm) = 0 % % or simply (assuming P(3), the coefficient of Z) is not zero... Z_mp = (dot(P,cm) - P(1)*x - P(2)*y)/P(3);
figure(200) scatter(x,y,2,Z_mp)
%% Correct z data zc = z-Z_mp;
Can someone help me?!
Bruno Luong
Bruno Luong on 18 Oct 2018
Is there any code in your question? See a bunch of comments and I'm not sure if there is any code inside.
Please format with care your question so we could see the status of where you are.

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 12 Mar 2015
Please read this and format. And what do you mean by "plan"? And why can't you just use the Euclidean Distance formula to get all the distances between all of the points and the mean location of all the points:
meanx = mean(x);
meany = mean(y);
meanz = mean(z);
allDistances = sqrt((x-meanx).^2+(y-meany).^2+(z-meanz).^2);

Jan on 12 Mar 2015
When you have a cloud of points and a plane freely oriented in 3D, you can measure the perpendicular distance by this transformation:
Find the 3D-rotation, which moved the plane parallel to the XY-plane. Then apply this rotation to the points also. Now the distance is a simple subtraction of the Z-values.
Another approach, if the plane is given by a point P and the normal vector N, while the points of the cloud are Q:
Dist = dot(Q - P, N, dim);
Where dim is 1 or 2 if the coordinates are stores as row or column vectors. The formula is nice, isn't it? You can find a lot of gems at WikiPedia...
  1 Comment
Ubaldo Pantaleo
Ubaldo Pantaleo on 20 Mar 2015
Thank you very much Simon for the suggestions! But how can i find the 3D-rotation and apply this rotation to the points?! I tried all these time but i found only how to center my points along the x axis. Thanks again for your time!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by