Effacer les filtres
Effacer les filtres

How to rotate a pointcloud data and align parallel with y-z axis?

35 vues (au cours des 30 derniers jours)
Mathanraj le 11 Sep 2023
Commenté : William Rose le 12 Sep 2023
I have a point cloud data with x,y and z values. It is little inclined in the y-axis little bit.I want to fit and well align with the axis. I have tried PCA based rotation but it causes over rotation. I have attached the image shows inclined data and excel file of xyz values. Please help me to rotate the data and align perfect with the axis. Thanks for your support.

Réponse acceptée

Matt J
Matt J le 11 Sep 2023
Modifié(e) : Matt J le 11 Sep 2023
[x1,y1,x2,y2]=deal(yz(v1,1), yz(v1,2), yz(v2,1), yz(v2,2));
t=atan2d(y2-y1,x2-x1); %rotation angle
YZ=(yz-mean(yz))*[cosd(t), -sind(t);sind(t), cosd(t)] + mean(yz);
scatter(yz(:,1), yz(:,2)); hold on; scatter(YZ(:,1), YZ(:,2)); hold off
legend('Initial','Corrected', Location='east')
ylabel Z; xlabel Y
  7 commentaires
Mathanraj le 12 Sep 2023
@William Rose Thanks for your detailed explanation and it really helps me to understand the concept of the Matt J's code. Yes, The data was collected by the scanner.
About the sheared look of the data, I used "axis equal" to rectify this issue. when I am using this command I can get the actual fitted look of the data without any shear. Is it okay to use this command?
And, sorry for the late reply.
William Rose
William Rose le 12 Sep 2023
Yes it is fine and good to use axis equal.

Connectez-vous pour commenter.

Plus de réponses (2)

Constantino Carlos Reyes-Aldasoro
This answer may solve your problem

William Rose
William Rose le 11 Sep 2023
[V,D]=eig(C); % eigenvectors and eigenvalues of the covariance matrix
The eigenvectors are the directions of the axes of the best fit ellipse. The square roots of the eigenvalues are the lengths of the axes. Multiply by 2 so they'll be easier to see on the plot.
Display the axis lengths and the standard deviations along x,y,z. The similarity suggests that we are on the right track.
0.0005 0.0499 0.0865 0.0007 0.0997 0.1731
Plot the data
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on; hold on
Make matrices to represent the endpoints of the best fit axes:
Add the axes to the plot
When you do it, you will be able to use the 3d rotate tool to spin the plot around and see the axes better.
Use the eigenvector directions to rotate the data. Scale the eigenvectors to make a rotation matrix.
for i=1:3
Rotate the data
Plot the rotated points:
figure(2); plot3(xyzRot(:,1),xyzRot(:,2),xyzRot(:,3),'k.');
title('Rotated Point Cloud');
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on;
After viewing the point cloud above from different angles, I think it is over-rotated about the X axis (middle panel below). See screenshot below of 3 views. The rotations about Y and Z look reasonable.
  1 commentaire
William Rose
William Rose le 11 Sep 2023
Modifié(e) : William Rose le 11 Sep 2023
[edit: correct typo and add description of alternate model]
A more complicated way would be to make a model I-beam with 6 adjustable parameters: L,W,D and orientation, which could be represented as 3 Euler angles, etc. (Assume the beam is made of infinitely thin plates.) Compute the sum squared distances from each point to the nearest part of the model I-beam. This would be tricky since you'd have to check distance from each point to the top plate, the bottom plate, and the middle plate, and take whichever distance is smallest. You may need 3 additional paramers for the center locaiton, if the points are not randomly sampled relative to the center.
Or the model beam is made of 3 infinite plates: 2 parallel, and one perpendicular to the other 2. The beam model has 4 parameters, not including orientation: its center location (x0,y0,z0) and the paprallel plate separation L. Infinite plates will make it easier to compute the distance to each of the three plates.
Then you use a fitting function like fmincon() to find the unknown parameters, including the 3 angles that minimize the sum squared distance. Then you would rotate by the inverse of the rotation specified by the 3 Euler angles.
Better yet, just eyeball it.

Connectez-vous pour commenter.




Community Treasure Hunt

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

Start Hunting!

Translated by