Math Girl
Math Girl

Reputation: 129

Find rotation matrix with two vectors

I want to find the rotation matrix between two vectors.

[0;0;1] = R * [0.0023;0.0019;0.9899]

How do I find the 3*3 rotation matrix?

Upvotes: 1

Views: 2738

Answers (2)

Hello World
Hello World

Reputation: 21

Your problem can be defined as a linear equation, say,

y = mx

where, y and x are matrices. Find m.

Solution:

m = x\y or m = mldivide(x,y)

Notice the backslash. It is not a forward slash / as Wolfie mentioned in his answer. For details see https://www.mathworks.com/help/matlab/ref/mldivide.html

Additional Details:

If x is a singular matrix, use pinv. See https://www.mathworks.com/help/matlab/ref/pinv.html for reference.

Upvotes: 0

Wolfie
Wolfie

Reputation: 30046

This is a simple rearrangement

% [0;0;1] = R * [0.0023;0.0019;0.9899];
% So ...
% [0;0;1] / [0.0023;0.0019;0.9899] = R
% This is a valid MATLAB command

R = [0;0;1] / [0.0023;0.0019;0.9899];
>> R =
    [ 0    0    0
      0    0    0
      0    0    1.0102 ]

We can validate this result

R * [0.0023;0.0019;0.9899]
>> ans =
    [0; 0; 1]

Upvotes: 2

Related Questions