How to determine the rotation matrix for rotating one vector to align with another ?

50 ビュー (過去 30 日間)
In matlab, the phased.Platform provide an example "Model Motion of Circling Airplane".
I'm interested in the detail of inner computing, so I do some research on the code.
[pos,vel,oax] = platform(T,accel)
The above code is to update the platform status and return 'postion', 'velocity' and 'OrientationAxes'. When I step into the 'platform' function, I found the update of OrientationAxes is computed by the inner function 'rotvv'. The following is copied from matlab:
%rotvv Rotation matrix for rotating one vector to align with another
% ROTMAT = rotvv(V1,V2) returns the rotation matrix, ROTMAT, that
% rotates the vector, V1, to be aligned with the vector, V2. Both V1 and
% V2 are originated from origin and are specified in the form of [x;y;z].
%
% ROTMAT is a 3x3 matrix. The rotation of the point can be achieved by
% left-multiplying ROTMAT with the point's coordinate vector [x;y;z].
%
% % Example:
% % Rotate a vector, [1;2;3] to be aligned with the y axis.
%
% v1 = [1;2;3];
% v2 = [0;1;0];
% v1r = rotvv(v1,v2)*v1
I do some experiments here.
Suppose we have:
u1=[2;4;6]
u2=[6;2;4]
we now use 'rotvv' provided by matlab to compute the rotation matrix, and get
r=rotvv(u1,u2);
r =
0.6790 0.6508 0.3398
-0.7165 0.6883 0.1133
-0.1602 -0.3204 0.9336
In otherside, when I use u1 x u2 as the rotation vector (axis) and Rodrigues' rotation matrix formula, I got one rotation matrix as:
r =
0.788571 0.377143 0.485714
-0.337143 0.925714 -0.171429
-0.514286 -0.0285714 0.857143
The above both matrix can do:
r * u1 || u2
here, '||' means 'align' or 'parallel' and in fact, we have
r * u1 = u2
Summary: In fact, we know that the rotation for a coordinate system can determine the unique rotation matrix, but rotation for a vector to another vector may have multiple rotation matrix.
Questions:
How do we choose the rotation matrix for the rotation from one vector to another?
Is there any special meaning for the computing method on the rotation matrix used by 'rotvv' ?
Is there any special meaning that 'rotvv' is used for the update of OrientationAxes in phased.Platform object? [when the rotation matrix is NOT unique]

採用された回答

David Goodmanson
David Goodmanson 2019 年 2 月 25 日
編集済み: David Goodmanson 2019 年 2 月 27 日
Hi Tao Feng.
One candidate is products of rotation matrices about x,y and z, basically Euler angles. Including traditional Euler angles and Tait-Bryan angles there are 12 ways to rotate around three axes with no two consectuve rotations about the same axis. There are also a lot of possibilities with active-passive, intrinsic-extrinsic, clockwise counterclockwise and who knows what else it's possible to have two conventions of. The code below uses an active transformation, fixed rotation axes (object moves, axes stay put) and ccw rotations with the rotation axis out of the page.
Two sets of rotations reproduced the Matlab result; these were z-y-z and z-x-z. I don't have rotvv and don't know what toolbox it's in. I thought it might be airplane oriented and that the rotations would be Tate-Bryan, but evidently not.
u1 = [2 4 6]';
u2 = [6 2 4]';
% z-y-z
th1 = atan2d(u1(2),u1(1));
M1z = RRz(-th1);
th2 = atan2d(u2(2),u2(1));
M2z = RRz(-th2);
v1 = M1z*u1;
v2 = M2z*u2;
b = atan2d(v2(1),v2(3));
a = atan2d(v1(1),v1(3));
My = RRy(b-a);
R = M2z'*My*M1z
R*u1
% z-x-z
th1 = atan2d(u1(2),u1(1));
M1z= RRz(90-th1);
th2 = atan2d(u2(2),u2(1));
M2z= RRz(90-th2);
v1 = M1z*u1;
v2 = M2z*u2;
b = atan2d(v2(3),v2(2));
a = atan2d(v1(3),v1(2));
Mx = RRx(b-a);
R = M2z'*Mx*M1z
R*u1
function R = RRx(theta)
% ccw rotation in DEGREES with rotation axis out of the page
R = [1 0 0
0 cosd(theta) -sind(theta)
0 sind(theta) cosd(theta)];
end
function R = RRy(theta)
% ccw rotation in DEGREES with rotation axis out of the page
R = [cosd(theta) 0 sind(theta)
0 1 0
-sind(theta) 0 cosd(theta)];
end
function R = RRz(theta)
% ccw rotation in DEGREES with rotation axis out of the page
R = [cosd(theta) -sind(theta) 0
sind(theta) cosd(theta) 0
0 0 1];
end
--
R = 0.6790 0.6508 0.3398
-0.7165 0.6883 0.1133
-0.1602 -0.3204 0.9336
ans = 6.0000 % u2
2.0000
4.0000
,
  1 件のコメント
Tao Feng
Tao Feng 2019 年 2 月 27 日
Thank you David. This is helpful. You save my time to find out how to reproduce Matlab result.

サインインしてコメントする。

その他の回答 (2 件)

Honglei Chen
Honglei Chen 2019 年 2 月 26 日
There is no special meaning of rotvv other than it's one of the implementation to rotate one vector to be parallel to another one. In fact at this point rotvv is an internal function and is not publicly documented.
Like you noticed and David explained above, this is not the unique solution.
Does this clarify your doubt? Thanks.

Qingyang Li
Qingyang Li 2019 年 4 月 6 日
Really nice work! It is really important for me.

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by