Plot the angle between two vectors
이전 댓글 표시
Hey MATLAB Answers!
I am trying to neatly plot the angle between vectors in 3D plots/figures as arcs with their respective angle. Specifically the angles between the x, y, and z-axis and Resultant. The values of which are DirectionAlpha, DirectionBeta, and DirectionGamma respectively. I have attached my code thus far and a picture of the kind of plot I wish to emulate.

%% Resultant Vector Workshop
clc;clearvars;close all %Clear the command window,Clear all workspace variables,Closes all figures
%% Begin Question 2-66
%Magnitude of Force for each Force
Force1 = 300; %Force of F_1 in [N].
Force2 = 500; %Force of F_2 in [N].
%If a Force uses an angle measurement put it here
Alpha1 = 60; %Angle between x-axis and F2 [Degrees].
Beta1 = 45;%Angle between y-axis and F2 [Degrees].
Gamma1 = 120;%Angle between z-axis and F2 [Degrees].
Theta1 = 45; %Angle of Theta1 in [Degrees].
Theta2 = 60;%Angle of Theta2 in [Degrees].
%Direction Vector for each Force
Vector1 = [-cosd(Theta2)*sind(Theta1), cosd(Theta2)*cosd(Theta1), sind(Theta2)]; %Direction vector of F1.
Vector2 = [cosd(Alpha1), cosd(Beta1), cosd(Gamma1)]; %Direction vector of F2.
%Each Force we are interested in as a vector
F1 = Force1*Vector1; %The magnitude and direction of F1 as a vector.
F2 = Force2*Vector2; %The magnitude and direction of F2 as a vector.
%Solve
Resultant = F1+F2; %Determine the Resultant Vector y adding force vectors
Magnitude = norm(Resultant); %Determine the Magnitude of the Resultant Vector
DirectionAlpha = acosd(Resultant(1)/Magnitude); %Determine the direction of the Resultant Vector [Degrees]
DirectionBeta = acosd(Resultant(2)/Magnitude); %Determine the direction of the Resultant Vector [Degrees]
DirectionGamma = acosd(Resultant(3)/Magnitude); %Determine the direction of the Resultant Vector [Degrees]
%% Extra Stuff
%The next lines of code make the information displayed to the command
%window more user friendly.
fprintf('F1 in Cartesian form is [%.2fi %.2fj %.2fk] [N]\n',F1(1),F1(2),F1(3)) %With formating send F1 to the command window
fprintf('F2 in Cartesian form is [%.2fi %.2fj %.2fk] [N]\n',F2(1),F2(2),F2(3)) %With formating send F2 to the command window
fprintf('The Resultant Vector in Cartesian form is [%.2fi %.2fj %.2fk] [N]\n',Resultant(1),Resultant(2),Resultant(3)) %With formating send the Resultant to the command window
fprintf('With Magnitude %.2f [N] and Direction %.2f [Degrees] from positive "X", %.2f [Degrees] from positive "Y", %.2f [Degrees] from positive "Z" \n',Magnitude,DirectionAlpha,DirectionBeta, DirectionGamma) %With formating send the Magnitude and Direction to the command window
figure()
hold on
plot3([0 0 0; F1(1),F1(2),F1(3)],[0 0 0; F2(1),F2(2),F2(3)],[0 0 0; Resultant(1),Resultant(2),Resultant(3)])
plot3([0 0 0; 0 0 Magnitude], [0 0 0; 0 Magnitude 0], [0 0 0; Magnitude 0 0],'--k')
Any help is greatly appreciated, even if thats a “this isn’t possible” as that would put my mind at ease.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
