How to find rotation matrix given two vectors in Matlab?

8 visualizzazioni (ultimi 30 giorni)
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 Commento
Roger Stafford
Roger Stafford il 5 Giu 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.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 5 Giu 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

Categorie

Scopri di più su Portfolio Optimization and Asset Allocation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by