How to find rotation matrix given two vectors in Matlab?

조회 수: 9 (최근 30일)
Lana C
Lana C 2016년 6월 5일
댓글: Roger Stafford 2016년 6월 5일
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