How to find rotation matrix given two vectors in Matlab?

9 次查看(过去 30 天)
Hiii! Is there a function in Matlab which finds rotation matrix R given two vectors v1,v2 size dx1 so that Rv1=v2? If no, how can I code this? Thanks for your help
  1 个评论
Roger Stafford
Roger Stafford 2016-6-5
Specifying v1 and v2 (of the same magnitude) does not uniquely determine a rotation matrix. Place the base of the two vectors at the origin and connect the other ends with a straight line segment. Any axis through the origin and lying in the plane of the perpendicular bisector of that line segment can be used as a rotation axis that will rotate v1 into v2.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2016-6-5
It depends on the result you want. Simple matrix right division will give you a mapping in ‘Method #1’, but if you want to estimate the angle, you have to use a parameter estimation approach in ‘Method #2’:
R = @(a) [cos(a) -sin(a); sin(a) cos(a)]; % Parametric Rotation Matrix
v1 = rand(2, 1) % Create Data
v2 = R(1.5)*v1 % Create Data
Rm = v2/v1; % Matrix Right Division - Method #1
v2s1 = Rm*v1 % Check Result
SSECF = @(b) sum((v2 - R(b)*v1).^2); % Sum-Squared_Error Cost Function
[B,SSE] = fminsearch(SSECF, 2); % Estimate Angle - Method #2
v2s = R(B)*v1 % Check Result

类别

Help CenterFile Exchange 中查找有关 Portfolio Optimization and Asset Allocation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by