Solving for rotation matrix: Align vector a with vector b, then rotate around vector b

Currently working on a quadcopter simulation. I have a desired thrust vector, t =sin(30)cos(45)a1+sin(30)sin(45)a2+cos(30)a3, and desired yaw angle, psi = 45. Because we are working with an under-actuated system, I am trying to solve for the rotation matrix that aligns the vector b3 = [0,0,1] (direction of thrust in the body-fixed frame of reference) with the direction of t. My code is included at the bottom. The problem is that it outputs an empty symbolic struct, with no warnings or errors otherwise:
What I am doing wrong? It is an issue with my theory, my implementation, or both? Thank you!
t = [sind(30) * cosd(45), sind(30) * sind(45), cosd(30)]; %desired thrust vector
psi = 45; %desired yaw angle
b3 = [0;0;1]; %body-fixed unit thrust vector
syms phi theta; %setting up to solve what's left of the rotation matrix
eqn = [[cosd(psi)*cosd(theta)-sind(phi)*sind(psi)*sind(theta), -cosd(phi)*sind(psi), cosd(psi)*sind(theta)+cosd(theta)*sind(phi)*sind(phi);
cosd(theta)*sind(psi)+cosd(psi)*sind(phi)*sind(theta), cosd(phi)*cosd(psi), sind(psi)*sind(theta)-cosd(theta)*sind(phi)*cosd(psi);
-cosd(phi)*sind(theta), sind(phi), cosd(phi)*cosd(theta)] * b3 == t/norm(t)]; %equation to be solved (general form of the rotation matrix multiplied by body-fixed thrust aligned with t)
S = solve(eqn,[phi theta]); %solve

 Accepted Answer

Here is an idea
  • Use dot product to calculate angle between vectors
  • Use cross product to calculate normal vector of a plane
You have normal vector and angle. COnstruct new rotation matrix

3 Comments

Thank you! This pointed me in the right direction, and I didn't even need the numerical solver. For anyone else aligning vector a with vector b and then rotating around vector b, here is my code:
t = [sind(30) * cosd(45), sind(30) * sind(45), cosd(30)];
b = [0;0;1];
psi = deg2rad(45);
v = cross(b,t);
s = norm(v);
c = dot(b,t);
phiB = psi;
uB = b;
uBhat = vector2ssMat(uB);
I = eye(3);
rotA = I+vector2ssMat(v)+(vector2ssMat(v)^2)*((1-c)/s^2);
rotB = I*cos(phiB)+uB*transpose(uB)*(1-cos(phiB))+uBhat*sin(phiB);
Rdes = rotA*rotB;
disp(Rdes);
Using ROdrigues formula
t = [sind(30) * cosd(45), sind(30) * sind(45), cosd(30)];
t = t/norm(t);
a = acos(dot(t,[0 0 1])); % angle to rotate (Z axis)
k = cross(t,[0 0 1]); % axis of rotation
k = k/norm(k);
K = zeros(3);
K([2 3 6]) = [k(3) -k(2) k(1)];
K = K - K';
ROT = @(a) eye(3) + sin(a)*K + (1-cos(a))*K^2; % matrix of rotation
vector2ssMat is an unrecognized function. how do i deal with this??

Sign in to comment.

More Answers (0)

Asked:

on 16 Mar 2020

Commented:

on 30 Jan 2021

Community Treasure Hunt

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

Start Hunting!