How to find rotation matrix from vector to another?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
2 votes
Share a link to this question
I have object with 3 vector. Let's say:
e1=[a1 b1 c1];
e2=[a2 b2 c2];
e3=[a3 b3 c3];
The global coordinator system (Ox, Oy, Oz)
n1=[1 0 0]; % Ox
n2=[0 1 0]; % Oy
n3=[0 0 1]; % Oz
How to find the rotation matrix R to rotate the object to match with xyz (e1 // n1, e2 // n2, e3 // n3) ? (// :parallel)
How to find R?

Accepted Answer
6 votes
R = [e1; e2; e3]
is the rotation matrix already, when we assume, that these are the normalized orthogonal vectors of the local coordinate system. To convert between the two reference systems all you need is R and R.' (as long as the translation is ignored).
A vector v=[x;y;z] in the global reference system is
R * v
in the local system. Then you can convert it back to the global system by:
R.' * R * v
and because this must reply v again you get the identity:
R.' * R == eye(3)
such that
R.' == inv(R) % except for rounding errors
You can split this rotation matrix to 3 matrices around specific axes to get a set of Euler or Cardan angles.
You will find many discussions in the net, which end in flamewars, because the users cannot decide if R or R' is the actual rotation, because sometimes the rotation of the vector is meant, and sometimes the rotation of the reference system. Each field of science has its own preferences in this point. See https://www.mathworks.com/matlabcentral/answers/313150-why-is-the-result-of-quaternion-rotation-an-matrix-multiplication-not-the-same
Maybe you are looking for the "helical axes", which can define the relative attitude between two coordinate systems by a vector of translation and a rotation around this vector. If so, please clarify this.
6 Comments
@ha ha: Yes? I've posted this link also. Perhaps helps you also:
Thank you so much.
But I'm still wonder. I try to check with a simple case. For simplicification, I assume e3//Oz already. So. I want to rotate only e1//Ox & e2//Oy only (plz see below photo and code)


n1=[1 0 0];n2=[0 1 0];n3=[0 0 1];e1=[1 3 0];e2=[3 -1 0];e3=[0 0 1];
R=[e1;e2;e3]; % your general formulas R
old=[2/3;2;0];
new=R*old;
But when running this code, the result of I is: [6.666;0;0] ???? Why is it incorrect?
e1, e2, e3 must be normalized and orthogonal to build a reference system. Did you see: R.' * R == eye(3)?
Rob Johnson
on 23 Jan 2018
Jan, I think it needs to be
R = [e1, e2, e3]
instead of
R = [e1; e2; e3]
Corrected code:
n1=[1 0 0];n2=[0 1 0];n3=[0 0 1];e1=[1 3 0];e2=[3 -1 0];e3=[0 0 1];%input data
e1 = e1/norm(e1);e2 = e2/norm(e2);e3 = e3/norm(e3);%e1, e2, e3 must be normalized firstly
R=[e1;e2;e3]; % your general formulas R
old=[2/3;2;0];
new=R*old;
or
clear;clc;P=[2/3 2 0;1 3 0];%input data in format kx3 matrix
n1=[1 0 0];n2=[0 1 0];n3=[0 0 1];e1=[1 3 0];e2=[3 -1 0];e3=[0 0 1];%input data
e1 = e1/norm(e1);e2 = e2/norm(e2);e3 = e3/norm(e3);%e1, e2, e3 must be normalized firstly
R=[e1;e2;e3]; % rotation matrix R: 3x3
new=(R*P')';%output data in format kx3 matrix
John Razzano
on 15 May 2018
Does this account for the fact that the new coordinate system is not only rotated but translated from the original? For example, if you use [0 0 0] as the "old" point you still get [0 0 0] after it has been transformed to the new frame using this method - I don't think this is correct unless I am misunderstanding something.
More Answers (0)
Categories
Find more on 座標変換と軌跡 in Help Center and File Exchange
Tags
See Also
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)