Calculate Rotation Matrix from vector in one cooridnate system to that vector in another coordinate system.

11 vues (au cours des 30 derniers jours)
If I have a vector:
[1, 0, 0]
and I know that when this vector is transformed it becomes:
[0, 1, 0]
I realize this is a rotation about the z-axis of -90 degrees. However, I need to create a MATLAB code that, between any two coordinate systems, can calculate the rotation matrix.
I've read that using Quaternions would be a great way to go, however I have not had a proper linear algebra course and therefore am trying to learn it on my own. My understanding of Quaternions is little to none. Also, my linear algebra is not that great to boot. I am not even sure if I am going about this correctly. I have look at many different Linear Algebra text books, but, of course, none of them show how to get the rotation matrix from the vector.
The code I have written so far looks like this:
function [ R ] = RotationMatrix(vec1, vec2)
x1 = [vec1(:,1), 0, 0];
y1 = [vec1(:,2), 0, 0];
z1 = [vec1(:,3), 0, 0];
x2 = [vec2(:,1), 0, 0];
y2 = [vec2(:,2), 0, 0];
z2 = [ vec2(:,3), 0, 0];
R = [x2;y2; z2]*(inv([x1;y1; z1]))
end
What I tried to do was turn each vector into a 3x3 so that I could take the inverse of the transformed vector and multiply it by the original vector to calculate the rotation matrix.
However, as you can see the test vectors I have chosen will not work because the inverse of those matrices are NaN (not a number).
Does anyone have any tips that could help me with this?
Thank you very much.
Caraline Griffith
  1 commentaire
Matt J
Matt J le 3 Nov 2013
I realize this is a rotation about the z-axis of 90 degrees.
It's also many other things. For example, both of the following rotation matrices map [1 0 0] to [0 1 0]
R1 =
0 0.5000 0.8660
1.0000 0 0
0 0.8660 -0.5000
R2 =
0 0.3420 0.9397
1.0000 0 0
0 0.9397 -0.3420

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 3 Nov 2013
Modifié(e) : Matt J le 3 Nov 2013
However, I need to create a MATLAB code that, between any two coordinate systems, can calculate the rotation matrix.
You need at least 3 vectors in each system to determine a coordinate rotation. Once you have three vectors, you can use this FEX file
to get the rotation matrix.
  3 commentaires
Matt J
Matt J le 4 Nov 2013
That would basically be diag([1,2,3]). Each row or column is one of the vectors you mention.
Caraline
Caraline le 4 Nov 2013
Alright, thank you. You've helped me quite a bit. I do need to construct my own code to compute the rotation matrix but is it alright if I use your code as a guide to know if I'm at least doing my computations correctly? I'll give the Horn's quaternion method a look and see what it's like.
Do you know of any way to calculate the rotation matrix and not use a quaternion based method? I'm just asking in case I cannot fully understand quaternions in the next week.
Thank you again Matt. You've been so helpful.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by