How to rotate or align point cloud ?
31 ビュー (過去 30 日間)
古いコメントを表示
Excuse me everyone! I have point cloud as shown in the figure. I want to rotate to the horizontal plane. The rotation point is the middle. How can I do it ? Thank you very much.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/844035/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/844035/image.jpeg)
0 件のコメント
採用された回答
Matt J
2021 年 12 月 25 日
編集済み: Matt J
2021 年 12 月 26 日
Since your point cloud is is not perfectly coplanar, you will need to fit a plane to it in order to determine the necessary rotation. You can do that with planarFit() from this downloadable package:
pfit=planarFit(plyRoi.Location.');
Having done this, you can also use some of the Hidden methods of the pfit object to do the rotation:
XYZ=plyRoi.Location;
x0=mean(XYZ);
R=pfit.vecrot(pfit.normal,[0,0,1]); %compute 3x3 rotation matrix
result=pointCloud((XYZ-x0)*R.'+x0); %rotated point cloud
14 件のコメント
Matt J
2021 年 12 月 26 日
編集済み: Matt J
2021 年 12 月 26 日
Here is the code I used, and the results I obtained,
XYZ=plyRoi.Location;
pfit=planarFit(XYZ');
x0=mean(XYZ);
R=pfit.vecrot(pfit.normal,[0,0,1]); %compute 3x3 rotation matrix
result=num2cell((XYZ-x0)*R'+x0,1); %rotated point cloud
[hF,h1]=plot(pfit); hold on
h2=scatter3(result{:},'filled','MarkerFaceColor','g'); hold off
axis(0.07*[-1,1,-1,1,-1,0])
view(-25,3)
legend([h1,hF,h2],'Old Cloud','Plane Fit','New Cloud',...
'location','north')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/844615/image.png)
その他の回答 (1 件)
Image Analyst
2021 年 12 月 25 日
You forgot to attach your data, which would have made it easier.
So I'd guess at something like
% Fit a line through the data.
coefficients = polyfit(x, y, 1);
% Then get the mean y
meany = mean(y);
% Get a fitted y
fittedy = polyval(coefficients, x);
% Then subtract the fitted values and add the vertical offset.
rotatedy = y - fittedy + meany;
plot(x, rotatedy, '.', 'MarkerSize', 10);
9 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!