how can i determine angle between 2 variables

1 次查看(过去 30 天)
how can i do/calculate the angle like in the ss below ,i know rBx,rBy and g
g=180/pi;
teta1=300;teta2=320;teta3=40;teta4=100;teta5=160; % in degrees
Alfa=deg2rad(teta1/g);aLfa=deg2rad(teta2/g); alFa=deg2rad(teta3/g);alfA=deg2rad(teta4/g);alfa=deg2rad(teta5/g);
rBx=-1*(r1*cos(Alfa)+r2*cos(aLfa)+r3*cos(alFa)+r4*cos(alfA)+r5*cos(alfa)+rAx)
rBy=-1*(r1*sin(Alfa)+r2*sin(aLfa)+r3*sin(alFa)+r4*sin(alfA)+r5*sin(alfa)+rAy)
  2 个评论
Opariuc Andrei
Opariuc Andrei 2021-1-5
编辑:Opariuc Andrei 2021-1-5
i knew about atan2 and i tried it before i posted but it did not gave the correct answear , i did a backtrace from the course pdf and got everything right/ identical up until alfaBg or where i'm supposed to do/find angle
%% input
%% values r, values z, values alfa_gi
r1=154; z1=30; ag1=267;
r2=122; z2=68; ag2=325;
r3=63; z3=105; ag3=49;
r4=68; z4=144; ag4=118;
r5=126; z5=188; ag5=180;
zA=226;
%% calculus
g=180/pi;
alfa1=ag1/g;
alfa2=ag2/g;
alfa3=ag3/g;
alfa4=ag4/g;
alfa5=ag5/g;
%% rAx si rAy
disp("rAx si rAy")
rAx=(-1)*(r1*z1*cos(alfa1)+r2*z2*cos(alfa2)+r3*z3*cos(alfa3)+r4*z4*cos(alfa4)+r5*z5*cos(alfa5))/zA
rAy=(-1)*(r1*z1*sin(alfa1)+r2*z2*sin(alfa2)+r3*z3*sin(alfa3)+r4*z4*sin(alfa4)+r5*z5*sin(alfa5))/zA
rA=sqrt(rAx^2+rAy^2) which results in 79.234 like in my pdf (value i'm supposed to get) but when i applied atan2(rAx,rAy)*g i was supposed to get the value in the ss 346.217
but instead i got alfa_A_g =103.7827 , i also tried doing deg2rad and rad2deg(atan2(...)) and didn't get the desired result

请先登录,再进行评论。

回答(1 个)

the cyclist
the cyclist 2021-1-5
You got the order of the inputs incorrect. It should be
atan2(rAy,rAx)*g
This will give a negative answer, measuring the angle "down" from the x-axis. If you add 360deg, you'll get the answer you want.

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by