MATLAB Answers

0

How can I transform a coordinates data into another 3-D space?

Asked by Heejun Rho on 21 Jun 2018
Latest activity Commented on by Heejun Rho on 23 Jun 2018
suppose that I have coordinates of 4 points X1, X2, X3, and X4 which have form of Xi = [xi1; xi2; xi3; xi4] for i = 1~4 . Their relative position to each other never change. But the whole coordinates were rotated in some way, and now I measured the coordinates of X'1, X'2, and X'3 but not X'4. In this case how can I find the coordinates of X'4 in new 3D space? What function can I use?
+) If there is a linear transform T with 3x3 size matrix that satisfies T*[X1 X2 X3] = [X'1 X'2 X'3] then is it unique?

  2 Comments

If there is a linear transform T with 3x3 size matrix that satisfies T[X1 X2 X3] = [X'1 X'2 X'3] then is it unique?*
But you said your Xi are 4x1 column vectors. How can they multiply with a 3x3 matrix?
You're right. Xi's must be 3x1 column vectors

Sign in to comment.

3 Answers

Answer by Matt J
on 22 Jun 2018
 Accepted Answer

You can use ABSOR (Download).
reg = absor([X1 X2 X3],[X'1 X'2 X'3]);
X'4= reg.R*X4 + reg.t;

  1 Comment

This is exactly what I was looking for. Thank you very much for nice code and example!

Sign in to comment.


Answer by Mark Saad on 21 Jun 2018

If you know angles through which they were rotated, you could try using rotation matrices.
https://www.mathworks.com/help/phased/ref/rotx.html

  0 Comments

Sign in to comment.


Answer by Anton Semechko on 21 Jun 2018

Code below demonstrates how to obtain rotation matrices between corresponding 3-tupples of non-collinear points in 3-space:
function three_point_rotation_demo
% Generate 3 random points and random rotation
% -------------------------------------------------------------------------
% 3 (noncollinear) data points
Xo=randn(3,3); % xyz-coordiantes along rows
% Random rotation matrix
r=randn(3,1);
r=r/norm(r); % direction of rotation vector
t=(178*rand(1)+1)*(pi/180); % rotation amount; between 1 and 179 degrees
r=t*r; % random rotation vector
K=zeros(3);
K(1,2)=-r(3);
K(1,3)= r(2);
K(2,3)=-r(1);
K=K-K'; % log of rotation matrix
Ro=expm(K); % rotation matrix corresponding to r
% Apply R to Xo to get X
X=(Ro*(Xo'))';
% Now, suppose that Ro (i.e., rotation that transforms Xo to X) is unknown.
% -------------------------------------------------------------------------
% Compute local (orthogonal) reference frame for X
d21=X(2,:)-X(1,:);
d31=X(3,:)-X(1,:);
e1=d21; e1=e1/norm(e1);
e2=d31-dot(e1,d31)*e1; e2=e2/norm(e2);
e3=cross(e1,e2); e3=e3/norm(e3);
F=[e1;e2;e3]'; % principal axes along columns
% Compute local (orthogonal) reference frame for Xo
d21=Xo(2,:)-Xo(1,:);
d31=Xo(3,:)-Xo(1,:);
e1=d21; e1=e1/norm(e1);
e2=d31-dot(e1,d31)*e1; e2=e2/norm(e2);
e3=cross(e1,e2); e3=e3/norm(e3);
Fo=[e1;e2;e3]';
% Rotation we seek (R) satisfies the equation F=R*Fo. Since Fo and F are
% orhogonal rotation matrices themselves, R=F*transpose(Fo)
R=F*(Fo');
% Now let's check that R is the same (up to numerical round off error) as
% Ro. If it is then R'*Ro should be a 3-by-3 matrix close to identity.
fprintf('Rotation residual:\n')
disp(R'*Ro)
% You can also verify that X=(R*(Xo'))', in which case, (R*(Xo'))'-X will be
% a 3-by-3 matrix with all entries very close to zero
fprintf('\nFrobenius norm of (R*(Xo''))''-X:\n')
disp(norm((R*(Xo'))'-X,'fro'))

  0 Comments

Sign in to comment.