rotation matrix 3D point data

18 Ansichten (letzte 30 Tage)
ha ha
ha ha am 11 Mai 2018
Bearbeitet: ha ha am 24 Nov. 2018
Let' say , I have the 3d point data in format [xi yi zi] of 176 point as show in attachment file test.txt. The 3d point data is as below figure (shown in OXY plane):
Now, I want to find rotate the data around axis OZ , and 1 edge of the rectangle // Ox, the other //Oy as the below image. How to find new coordinate?

Akzeptierte Antwort

ha ha
ha ha am 11 Mai 2018
Bearbeitet: ha ha am 11 Mai 2018
FINAL ANSWER:
%%Load input 3D data
clear;clc;filename = 'test.txt'; inputfile = importfile(filename);
P = inputfile(:,1:3);%get data=coordinate(x,y,z) from set of data
x = P(:,1) ; y = P(:,2) ;z = P(:,3) ; % get (x,y,z) coordinate
x0 = x-mean(x) ; y0 = y-mean(y) ; z0 = z-mean(z) ; % remove mean
P1 = [x0 y0 z0] ; %this step to bring the coord of P near to the origin. The new coord will be created
scatter3(P1(:,1),P1(:,2),P1(:,3),'b.');%plot new coord of P1
HA=[min(P1(:,1)) min(P1(:,2)) max(P1(:,3))+1];%just for better visualaztion
hold on;scatter3(HA(:,1),HA(:,2),HA(:,3),'g.');%just for better visualaztion
%%Finding principal vector of 3D data P
PCA=pca(P);
e1=PCA(:,1)'; e2=PCA(:,2)' ;e3=PCA(:,3)'; % 3 principal vector(3 eigenvector) of "input data"
n1=[1 0 0] ; n2=[0 1 0] ; n3=[0 0 1]; % 3 unit vector Ox,Oy,Oz
transformation matrix from "e" space to "n" space
R=[e2;e1;e3]; % rotation matrix , match with xyz (e1//n2, e2//n1, e3//n3)
% R=[e1;e2;e3]; % rotation matrix , match with xyz (e1//n1, e2//n2, e3//n3)
% R=[e3;e2;e1]; % If e1//n3, e2//n2, e3//n1
%%Finding the new rotate data
newdata1=(R*P1')';%new data corresponding to P1 coordinate
hold on; scatter3(newdata1(:,1),newdata1(:,2),newdata1(:,3),'r.');
newdata=[newdata1(:,1)+mean(x),newdata1(:,2)+mean(y),newdata1(:,3)+mean(z)];
%%Plot the original & rotation 3D data
figure;scatter3(P(:,1),P(:,2),P(:,3),'b.');
hold on;scatter3(newdata(:,1),newdata(:,2),newdata(:,3),'r.');
HA=[min(P(:,1)) min(P(:,2)) max(P(:,3))+1];%just for better visualaztion
hold on;scatter3(HA(:,1),HA(:,2),HA(:,3),'g.');%just for better visualaztion
legend('original data(P)','rotated data(newdata)');title({'Plot the rotation matrix 3D point data';'(FINAL RESULT)'});

Weitere Antworten (1)

KSSV
KSSV am 11 Mai 2018
You need to rotate your data by certain angle to achieve what you shown. You need to know Affine transformations. Check the below code.
coor = load('test.txt') ;
x = coor(:,1) ; y = coor(:,2) ; % (x,y) points
x0 = x-mean(x) ; y0 = y-mean(y) ; % remove mean
A = [x0 y0 ones(size(x))] ;
th = 38 ; % angle in degrees by which data is rotated
T = [cosd(th) sind(th) 0 ; -sind(th) cosd(th) 0 ; 0 0 1] ; % TRansformation matrix
At = A*T ; % rotate the dat
At = [At(:,1)+mean(x) At(:,2)+mean(y)] ; % Add mean to At
plot(x,y,'.r') ;
hold on
plot(At(:,1),At(:,2),'.b') ;
  4 Kommentare
Jan
Jan am 11 Mai 2018
@ha ha: Showing a 2D view was confusing. But the problem can be reduced to 2D easily by finding the plane nearest to all points at first and use e.g. fitgeotrans on the points projected into this plane.
ha ha
ha ha am 11 Mai 2018
ok. agree, but where 38 degree come from? I guess this is the angle between rectangle & Oy?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Preprocessing Data finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by