# remove point cloud tilt by plane fit

15 views (last 30 days)
Istvan on 30 Apr 2018
Commented: Brian on 2 Aug 2019
Hello,
I have a point cloud created from vectors as PCdata = pointCloud([X;Y;Z]'); This represents data from a single plane, with an obvious tilt (2D slope) on it, which I would like to get rid of, so I end up with a point cloud on a horizontal plane.
I managed to fit a plane by:
[model1,inlierIndices,outlierIndices] = pcfitplane(PCdata,100);
...but can anyone tell me how to generate the new point cloud, by either: - subtracting the fitted plane from the original PC = new PC that is at a height around 0 and horizontal ? - subtracting the fitted plane's 2D slope (along x and y) = new PC that is horizontal (but has same mean Z) ?
Any other method you can suggest would also be great, I thought plane fitting would be the obvious way.
Thank you!
Moazza on 6 Jun 2018
There is an example in MATLAB, which tell how to subtract the fitted planefrom the original PC and then you get the remaining PC. Please check DetectMultiplePlanesFromPointCloudExample in Matlab R2017a

Ben Drebing on 4 May 2018
Edited: Ben Drebing on 4 May 2018
I think the fastest way to do this might be to use "pctransform" to rotate your pointcloud. Check out this example:
The only tough part will be defining your rotation matrix (A in the example) and the missing piece of the puzzle is knowing what angles to use to create the matrix. Luckily, the "model1" variable from your plane fit contains a normal vector. This vector basically points "up" in relation to your plane. If you find the angles between this vector and the vector [0,0,1], this will give you the angles needed to rotate the plane until its normal vector is pointing straight up. I thought this link has a pretty good explanation:

Dimitrios Panagiotidis on 2 Apr 2019
Well, I would agree with what Ben said, regarding the trasnformation of your point cloud, however a way that might work is to rotate your point cloud using the CloudCompare software (it is a software particlualrly designed for point clouds processing) or at least you can use it to extract in .txt your tranformation matrix and continue with the rest in Matlab. You can rotate the point cloud there relatively easy, it has many options and a GUI where you can directly see any applied transformation on it: If you wish to do that exclusively in Matlab then consider this example:
theta = pi/2
Around X-axis:
X = x;
Y = y*cos(theta) - z*sin(theta);
Z = y*sin(theta) + z*cos(theta);
Around Y-axis:
X = x*cos(theta) + z*sin(theta);
Y = y;
Z = z*cos(theta) - x*sin(theta);
Around Z-axis:
X = x*cos(theta) - y*sin(theta);
Y = x*sin(theta) + y*cos(theta);
Z = z;
it wont be an easy task because you need to know the angle for your rotation and also in which axis to apply it :-) that might get lot of time and effort :-) good luck
Brian on 2 Aug 2019
I have a similar task and am trying to use the model.normal output information from using the pcfitplane command that gives the normal vector to the best fit plane of the point cloud. I've calculated the angles that the normal makes with the x,y,z axis' yet am not getting the point cloud to rotate to the horizontal orientation. I've tried using the pctransform as well as making matrices to rotate in x, y, z.. The link that I saw before had different matrices than above though. I will try these and see.
Brian Charles

### Categories

Find more on Point Cloud Processing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!