Good evening, we have a point cloud and have applied an first rotation to align the point cloud along the y-axis. Now we have a problem with a second rotation
clear all
close all
clc
%%
movingReg=pcread(‘v65_ts40_repeatibility_four9.ply’);
figure, pcshow(movingReg), view([0 0 ]), axis on, xlabel(‘x [mm]’), ylabel(‘y [mm]’), zlabel(‘z [mm]’)
%% roi dove ci sono i quattro fori
roi = [360 540 -155 -130 40 115]; % DA CAD
indices = findPointsInROI(movingReg,roi);
ptCloudB = select(movingReg,indices);
figure, pcshow(ptCloudB)
%% punto medio della nuvola di punti
centro=[mean(ptCloudB.Location(:,1)) mean(ptCloudB.Location(:,2)) mean(ptCloudB.Location(:,3))];
%% codice dato da Paolo per l’allineamento della nuvola
XYZ=[ptCloudB.Location(:,1) ptCloudB.Location(:,2) ptCloudB.Location(:,3)];
xyz0=mean(XYZ,1);
A=XYZ-xyz0;
[~,~,V]=svd(A,0);
a=cross(V(:,3),[0;0;1]);
T=makehgtform(‘axisrotate’, a, -atan2(norm(a),V(3,3)));
R=T(1:3,1:3);
A_rot = A*R;
% A_rot_pt=pointCloud(A_rot);
A_rot_p(:,1)=A_rot(:,1);
A_rot_p(:,3)=A_rot(:,2);
A_rot_p(:,2)=A_rot(:,3);
A_rot_p=pointCloud(A_rot_p);
figure, pcshow(A_rot_p),axis on, xlabel(‘x [mm]’), ylabel(‘y [mm]’), zlabel(‘z [mm]’)
%% applico una seconda svd
XYZ2=[A_rot_p.Location(:,1) A_rot_p.Location(:,2) A_rot_p.Location(:,3)];
xyz0_2=mean(XYZ2,1);
A=XYZ2-xyz0_2;
[~,~,V]=svd(A,0);
a=cross(V(:,1),[0;1;0]);%cross(V(:,2),[0;1;0]);
% T=makehgtform(‘zrotate’, -atan2(norm(a),V(2,1)));
if (V(1,2))>0
T=makehgtform(‘axisrotate’, [0 1 0], -atan2(norm(a),V(1,2)));
else
T=makehgtform(‘axisrotate’, [0 1 0], -atan2(norm(a),-V(1,2)));
endclear all
close all
clc
%%
movingReg=pcread(‘v65_ts40_repeatibility_four9.ply’);
figure, pcshow(movingReg), view([0 0 ]), axis on, xlabel(‘x [mm]’), ylabel(‘y [mm]’), zlabel(‘z [mm]’)
%% roi dove ci sono i quattro fori
roi = [360 540 -155 -130 40 115]; % DA CAD
indices = findPointsInROI(movingReg,roi);
ptCloudB = select(movingReg,indices);
figure, pcshow(ptCloudB)
%% punto medio della nuvola di punti
centro=[mean(ptCloudB.Location(:,1)) mean(ptCloudB.Location(:,2)) mean(ptCloudB.Location(:,3))];
%% codice dato da Paolo per l’allineamento della nuvola
XYZ=[ptCloudB.Location(:,1) ptCloudB.Location(:,2) ptCloudB.Location(:,3)];
xyz0=mean(XYZ,1);
A=XYZ-xyz0;
[~,~,V]=svd(A,0);
a=cross(V(:,3),[0;0;1]);
T=makehgtform(‘axisrotate’, a, -atan2(norm(a),V(3,3)));
R=T(1:3,1:3);
A_rot = A*R;
% A_rot_pt=pointCloud(A_rot);
A_rot_p(:,1)=A_rot(:,1);
A_rot_p(:,3)=A_rot(:,2);
A_rot_p(:,2)=A_rot(:,3);
A_rot_p=pointCloud(A_rot_p);
figure, pcshow(A_rot_p),axis on, xlabel(‘x [mm]’), ylabel(‘y [mm]’), zlabel(‘z [mm]’)
%% applico una seconda svd
XYZ2=[A_rot_p.Location(:,1) A_rot_p.Location(:,2) A_rot_p.Location(:,3)];
xyz0_2=mean(XYZ2,1);
A=XYZ2-xyz0_2;
[~,~,V]=svd(A,0);
a=cross(V(:,1),[0;1;0]);%cross(V(:,2),[0;1;0]);
% T=makehgtform(‘zrotate’, -atan2(norm(a),V(2,1)));
if (V(1,2))>0
T=makehgtform(‘axisrotate’, [0 1 0], -atan2(norm(a),V(1,2)));
else
T=makehgtform(‘axisrotate’, [0 1 0], -atan2(norm(a),-V(1,2)));
end clear all
close all
clc
%%
movingReg=pcread(‘v65_ts40_repeatibility_four9.ply’);
figure, pcshow(movingReg), view([0 0 ]), axis on, xlabel(‘x [mm]’), ylabel(‘y [mm]’), zlabel(‘z [mm]’)
%% roi dove ci sono i quattro fori
roi = [360 540 -155 -130 40 115]; % DA CAD
indices = findPointsInROI(movingReg,roi);
ptCloudB = select(movingReg,indices);
figure, pcshow(ptCloudB)
%% punto medio della nuvola di punti
centro=[mean(ptCloudB.Location(:,1)) mean(ptCloudB.Location(:,2)) mean(ptCloudB.Location(:,3))];
%% codice dato da Paolo per l’allineamento della nuvola
XYZ=[ptCloudB.Location(:,1) ptCloudB.Location(:,2) ptCloudB.Location(:,3)];
xyz0=mean(XYZ,1);
A=XYZ-xyz0;
[~,~,V]=svd(A,0);
a=cross(V(:,3),[0;0;1]);
T=makehgtform(‘axisrotate’, a, -atan2(norm(a),V(3,3)));
R=T(1:3,1:3);
A_rot = A*R;
% A_rot_pt=pointCloud(A_rot);
A_rot_p(:,1)=A_rot(:,1);
A_rot_p(:,3)=A_rot(:,2);
A_rot_p(:,2)=A_rot(:,3);
A_rot_p=pointCloud(A_rot_p);
figure, pcshow(A_rot_p),axis on, xlabel(‘x [mm]’), ylabel(‘y [mm]’), zlabel(‘z [mm]’)
%% applico una seconda svd
XYZ2=[A_rot_p.Location(:,1) A_rot_p.Location(:,2) A_rot_p.Location(:,3)];
xyz0_2=mean(XYZ2,1);
A=XYZ2-xyz0_2;
[~,~,V]=svd(A,0);
a=cross(V(:,1),[0;1;0]);%cross(V(:,2),[0;1;0]);
% T=makehgtform(‘zrotate’, -atan2(norm(a),V(2,1)));
if (V(1,2))>0
T=makehgtform(‘axisrotate’, [0 1 0], -atan2(norm(a),V(1,2)));
else
T=makehgtform(‘axisrotate’, [0 1 0], -atan2(norm(a),-V(1,2)));
end point cloud, data rotation MATLAB Answers — New Questions