How to find rotation matrix given two vectors in Matlab?

10 vues (au cours des 30 derniers jours)
Lana C
Lana C le 5 Juin 2016
Commenté : Roger Stafford le 5 Juin 2016
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 commentaire
Roger Stafford
Roger Stafford le 5 Juin 2016
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.

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 5 Juin 2016
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

Catégories

En savoir plus sur Portfolio Optimization and Asset Allocation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by