How to calculate a rotation matrix between two 3d points

조회 수: 180 (최근 30일)
alessiadele
alessiadele 2019년 2월 20일
댓글: Kevin Hughes 2022년 12월 9일
Hi everyone!
I have two vectors that represent one point with respect to two different reference systems, eg, p0=[x0, y0, z0] and p1=[x1, y1, z1]; I need to know wich is the rotation matrix that transform the vector p1 to the vector p0. I absolutely don't know the angle rotation, neither the axis around wich the rotation is carried out.
I've tried to use 'vrrotvec' function and then 'vrrotvec2mat' to convert rotation from axis-angle to matrix representation; in theory, if I use this two functions to calculate the rotation matrix R between p1 and p0, when I compute R*p1 I should obtain p0, but the outcome is a vector different from p0.
I hope I've been clear!
Do you have any suggestion?
Thank you!!

채택된 답변

Jos (10584)
Jos (10584) 2019년 2월 20일
편집: Jos (10584) 2019년 2월 20일
You can used dot and cross products to get the rotation matrix:
% two random 3D vectors
p0 = randi(10,3,1)
p1 = randi(10,3,1)
% calculate cross and dot products
C = cross(p0, p1) ;
D = dot(p0, p1) ;
NP0 = norm(p0) ; % used for scaling
if ~all(C==0) % check for colinearity
Z = [0 -C(3) C(2); C(3) 0 -C(1); -C(2) C(1) 0] ;
R = (eye(3) + Z + Z^2 * (1-D)/(norm(C)^2)) / NP0^2 ; % rotation matrix
else
R = sign(D) * (norm(p1) / NP0) ; % orientation and scaling
end
% R is the rotation matrix from p0 to p1, so that (except for round-off errors) ...
R * p0 % ... equals p1
inv(R) * p1 % ... equals p0
  댓글 수: 4
Lucien Robinault
Lucien Robinault 2021년 3월 4일
Hello,
First of all, thanks a lot for this.
Would you have any references on this way of doing by any chances? It is definitly not the way it is explained on all the ressources on rotation matrix (which I couldn't manage to get working anyway), so I would really like to finally understand the process involved in finding the rotation matrix.
Thanks a lot
Kevin Hughes
Kevin Hughes 2022년 12월 9일
Thanks this was very helpfull

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by