Plane fitting using 3D points
100 views (last 30 days)
Show older comments
Ashicka Banu Mubarak
on 26 Mar 2019
Commented: VIGNESH BALAJI
on 21 Jul 2023
I have my 3D points(lidar data) as a text file. can anyone suggest me a method for fitting the plane.
Accepted Answer
Star Strider
on 26 Mar 2019
Try this:
P = bsxfun(@times, rand(49, 3), [1 10 100]); % Create Matrix [x, y, z]
B = [P(:,1), P(:,2), ones(size(P,1),1)] \ P(:,3); % Linear Regression
xv = [min(P(:,1)) max(P(:,1))];
yv = [min(P(:,2)) max(P(:,2))];
zv = [xv(:), yv(:), ones(2,1)] * B; % Calculate Regression Plane
figure
stem3(P(:,1), P(:,2), P(:,3), '.')
hold on
patch([min(xv) min(xv) max(xv) max(xv)], [min(yv) max(yv) max(yv) min(yv)], [min(zv) min(zv) max(zv) max(zv)], 'r', 'FaceAlpha',0.5)
hold off
grid on
xlabel('X')
ylabel('Y')
producing (with this set of random data):
7 Comments
VIGNESH BALAJI
on 21 Jul 2023
@Star Strider When I use your method, the plane fit for a 3D dataset is not a good fit, maybe because instead of regression you can calculate mean of the points and find a basis of the plane and fit the plane to the data.
When I used Plane Fit (Affine fit function to fit the data) https://nl.mathworks.com/matlabcentral/fileexchange/43305-plane-fit . I got a better fit
More Answers (0)
See Also
Categories
Find more on Interpolation 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!