Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Computing rotation matrix from vectors

Subject: Computing rotation matrix from vectors

From: Rahman

Date: 3 Dec, 2007 07:41:16

Message: 1 of 13

I have 4 vectors in 2 different 3D coordinate. The origin of
coordinates is the same point.Question is how I can compute
the rotation matrix between these 2 coordinates?

Any Idea?

Thanks
Rahman

Subject: Computing rotation matrix from vectors

From: Bruno Luong

Date: 3 Dec, 2007 08:03:54

Message: 2 of 13

"Rahman " <john.doe.nospam@mathworks.com> wrote in message
<fj0bus$1i$1@fred.mathworks.com>...
> I have 4 vectors in 2 different 3D coordinate. The origin of
> coordinates is the same point.Question is how I can compute
> the rotation matrix between these 2 coordinates?
>
> Any Idea?
>
> Thanks
> Rahman

If A is 4 x 3 matrix (four vectors V put in columns) in
Coordinate system #1.
and B is 4 x 3 matrix of V in coordinate system #2.

What you want is a orthogonal matrix (3x3) matrix (rotation
matrix) such that B = Q*A.

Then solving Q can be accomplished by

Q = B/A

Bruno

Subject: Computing rotation matrix from vectors

From: Rahman

Date: 3 Dec, 2007 08:42:20

Message: 3 of 13

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fj0d9a$goi$1@fred.mathworks.com>...
> "Rahman " <john.doe.nospam@mathworks.com> wrote in message
> <fj0bus$1i$1@fred.mathworks.com>...
> > I have 4 vectors in 2 different 3D coordinate. The origin of
> > coordinates is the same point.Question is how I can compute
> > the rotation matrix between these 2 coordinates?
> >
> > Any Idea?
> >
> > Thanks
> > Rahman
>
> If A is 4 x 3 matrix (four vectors V put in columns) in
> Coordinate system #1.
> and B is 4 x 3 matrix of V in coordinate system #2.
>
> What you want is a orthogonal matrix (3x3) matrix (rotation
> matrix) such that B = Q*A.
>
> Then solving Q can be accomplished by
>
> Q = B/A
>
> Bruno
 
Thanks for fast answer.
In other words Q= inv(A) * B. But as you know inverse matrix
should be square!
It is possible use this way with least square method, but
problem is the computing rotation matrix doesnt have the
rotation matrix properties, or in other words its accuracy
is very low.

Another help?

Subject: Computing rotation matrix from vectors

From: Bruno Luong

Date: 3 Dec, 2007 08:57:18

Message: 4 of 13

"Rahman " <john.doe.nospam@mathworks.com> wrote in message
<fj0fhc$dd1$1@fred.mathworks.com>...

> but
> problem is the computing rotation matrix doesnt have the
> rotation matrix properties, or in other words its accuracy
> is very low.

What????

If your inputs are consistent, you will get a rotation
matrix at the machine precision accuracy.

If your inputs are not in the form B = Q*A with Q
orthogonal, then your problem do not have a solution.

Bruno

Subject: Computing rotation matrix from vectors

From: Bruno Luong

Date: 3 Dec, 2007 09:36:14

Message: 5 of 13

%
% Generate a random rotation matrix
%
[Q dummy]= qr(rand(3));
Q

%
% Random 4 vectors in R^3 in the first coordinate
%
A=randn(3,4);
B=Q*A; % Coordinates in the second system

%
% Estimates Q from A and B
%
Qest = B/A

%
% Do this if you don't trust your data and
% want to reorrthogonalize Qest
%
[U,S,V]=svd(Qest);
Qest = U*V'

Bruno

Subject: Computing rotation matrix from vectors

From: Rahman

Date: 3 Dec, 2007 12:10:08

Message: 6 of 13

Thanks. I did but for my data, the result matrix is 5x4!!!
Please be aware that my data come from experiment, so surly
they are not perfect and need to choose the optimize matrix.

Subject: Computing rotation matrix from vectors

From: Bruno Luong

Date: 3 Dec, 2007 13:34:16

Message: 7 of 13

"Rahman " <john.doe.nospam@mathworks.com> wrote in message
<fj0rn0$9h2$1@fred.mathworks.com>...
> Thanks. I did but for my data, the result matrix is 5x4!!!
> Please be aware that my data come from experiment, so surly
> they are not perfect and need to choose the optimize matrix.

Something is very wrong. How many vectors do you have? I
though you have 4 vectors in R^3, in two coordinate systems.

If you calculate
Q = B/A where A and B are (3 x n) matrices you must get (3 x
3) matrix. The solution is unique if and only if rank(A)=3.

You can use eig() on Q to find out rotation-axis and
rotation angle.

Bruno

Subject: Computing rotation matrix from vectors

From: Roger Stafford

Date: 3 Dec, 2007 19:03:48

Message: 8 of 13

"Rahman " <john.doe.nospam@mathworks.com> wrote in message <fj0bus$1i
$1@fred.mathworks.com>...
> I have 4 vectors in 2 different 3D coordinate. The origin of
> coordinates is the same point.Question is how I can compute
> the rotation matrix between these 2 coordinates?
>
> Any Idea?
>
> Thanks
> Rahman
-------
  When you say "4 vectors in 2 different 3D coordinate", do you mean two
vectors in one coordinate system and the same two vectors expressed in terms
of a rotated coordinate system, as in the rotation of a rigid body? That is what
would be required to determine the rotation of the rigid body. Presumably the
lengths of the two vectors and the angles between them remain unchanged if
the rotation is to be about the common origin.

Roger Stafford

Subject: Computing rotation matrix from vectors

From: Roger Stafford

Date: 3 Dec, 2007 19:03:54

Message: 9 of 13

"Rahman " <john.doe.nospam@mathworks.com> wrote in message <fj0bus$1i
$1@fred.mathworks.com>...
> I have 4 vectors in 2 different 3D coordinate. The origin of
> coordinates is the same point.Question is how I can compute
> the rotation matrix between these 2 coordinates?
>
> Any Idea?
>
> Thanks
> Rahman
-------
  When you say "4 vectors in 2 different 3D coordinate", do you mean two
vectors in one coordinate system and the same two vectors expressed in terms
of a rotated coordinate system, as in the rotation of a rigid body? That is what
would be required to determine the rotation of the rigid body. Presumably the
lengths of the two vectors and the angles between them remain unchanged if
the rotation is to be about the common origin.

Roger Stafford

Subject: Computing rotation matrix from vectors

From: Bruno Luong

Date: 3 Dec, 2007 19:38:27

Message: 10 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fj1juq$hr7$1@fred.mathworks.com>...
> Presumably the
> lengths of the two vectors and the angles between them
remain unchanged if
> the rotation is to be about the common origin.
>

Huumm, rotation in 3D does not necessary conserve angle.
Example, If you rotate about z axis about say 90 degree. The
vector (0,0,1) and transform to (0,0,1), and the angle
between them is of course 0 degree, and not 90 degree.

All rotations in R3 is a group, called SO(3). They are
orthogonal (3x3) matrix, i.e., Q*Q' = I.

Any element of SO(3) has 3 eigen-values (1, exp(i*theta),
exp(-i*theta)). The eigen-vector corresponds to 1 is the
rotation axis. Theta is the rotation angle.

The rotation conserve angle generally for vectors that are
perpendicular to the rotation axis, i.e., in the span of two
complex eigen-vectors.

Bruno

Subject: Computing rotation matrix from vectors

From: Bruno Luong

Date: 3 Dec, 2007 19:47:36

Message: 11 of 13

Forget what I just wrote, I simply miss-understood Roger (he
wrote about angle of two vector before and after
transformation, and this is of course correct). Apologize.

Bruno

Subject: Computing rotation matrix from vectors

From: Peter Perkins

Date: 4 Dec, 2007 14:49:07

Message: 12 of 13

Rahman wrote:
> I have 4 vectors in 2 different 3D coordinate. The origin of
> coordinates is the same point.Question is how I can compute
> the rotation matrix between these 2 coordinates?

If you have access to the Statistics Toolbox, I think you'll find that
PROCRUSTES does this nicely:

 >> A = randn(4,3); % four random vectors in 3-D
 >> [U,S,V] = svd(randn(3)); T = U*V'; % random orthogonal matrix
 >> T
T =
      -0.91586 -0.14665 -0.37375
      0.084785 0.83926 -0.53707
       0.39244 -0.52357 -0.75621
 >> B = A*T; % rotate A
 >>
 >> [d,B1,tr] = procrustes(B,A);
 >> tr.T % rotation component: same as original T
ans =
      -0.91586 -0.14665 -0.37375
      0.084785 0.83926 -0.53707
       0.39244 -0.52357 -0.75621
 >> tr.c % translation component: 0
ans =
    2.2204e-16 5.5511e-17 0
    2.2204e-16 5.5511e-17 0
    2.2204e-16 5.5511e-17 0
    2.2204e-16 5.5511e-17 0
 >> tr.b % scale component: 1
ans =
             1

Hope this helps.

- Peter Perkins
   The MathWorks, Inc.

Subject: Computing rotation matrix from vectors

From: Rahman

Date: 6 Dec, 2007 05:19:42

Message: 13 of 13

Thank you very much. Ya, this is complete correct. I found a
page about it and then could understand and find the
function. For who has the same problem this Link is very useful.
http://kwon3d.com/ search between theories: Computation of
the Rotation Matrix

Cheers
Rahman

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
coordinate Rahman 3 Dec, 2007 03:45:06
vector Rahman 3 Dec, 2007 03:45:06
coordinates Rahman 3 Dec, 2007 02:45:03
vectors Rahman 3 Dec, 2007 02:45:03
rotation matrix Rahman 3 Dec, 2007 02:45:03
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics