Setting a 3rd vector with specific angles to 2 other vectors
Afficher commentaires plus anciens
Hello, I want to define 2 vectors in the 3D coordinate space (A and B) and the angle between them should be 92.1 degrees. I then want to set a 3rd vector (C) which will be at a 84.4 degrees angle with A and 86.2 degrees with B. Here is the code I am using for that:
% Define angles I want
A_B = 92.1;
A_C = 84.4;
B_C = 86.2;
% Create a unit vector A
A = [0; 0; 1];
% Define B by rotating A by A_B angle around x-axis
rotationx = [1 0 0 ; ...
0 cosd(A_B) -sind(A_B) ; ...
0 sind(A_B) cosd(A_B)] ;
B = rotationx*A;
% Define C with respect to A by rotating A by A_C angle around y-axis
rotationy = [cosd(A_C) 0 sind(A_C) ; ...
0 1 0 ; ...
-sind(A_C) 0 cosd(A_C)];
C = rotationy*A;
% Calculate the angle difference between current C and B
angleCurrent = atan2d(norm(cross(C,B)), dot(C,B));
% Find the difference between the current angle and the C-B value I want to
% get
angleDiff = B_C-angleCurrent;
% Move C again around the z-axis
rotationz = [cosd(angleDiff) -sind(angleDiff) 0; ...
sind(angleDiff) cosd(angleDiff) 0; ...
0 0 1];
C = rotationz*C;
With this code I get the following values. Looks like the angle between A_B and A_C is fine, but the B_C is very slightly off. I guess I should move my C vector around the y and z axes at the same time instead of moving it in separate steps with repsect to A and B. Am I correct? If so, how should the rotation matrix look? Thanks!
A_B = 92.1;
A_C = 84.4;
B_C = 86.2223;
Réponse acceptée
Plus de réponses (1)
Ozzy
le 28 Oct 2021
0 votes
1 commentaire
David Goodmanson
le 29 Oct 2021
Huseyin,
I mentioned that what you were doing was the start of an iterative process. The method I used is not iterative. Starting with A, it defines C by using a known rotation angle (A_C) about y, followed by an unknown rotation angle theta about z. It finds the dot product of B and C, which has to equal cosd(B_C), and solves for sind(theta) algebraically in one step. Then it uses that value of theta to find C.
Catégories
En savoir plus sur Axes Transformations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!