Changing the atan function so that it ranges from 0 to 2*pi
atand and atan2d
"atan" function
how to write ( a=(arctan(b/c)*pi*r)/90) in Matlab 2014
Hi everyone,
I was using the following formula to find the angle between three coordinate values (i.e., P1, P0, P2; finding angle at P0)
ang = (180/pi)*(atan2(abs(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0)));
formula taken from: https://in.mathworks.com/matlabcentral/answers/57736-how-to-calculate-degree-between-3-points-in-matlab#answer_69886
So, it worked fine when I took the coordinate values as ;
P0 = [3,1];P1 = [1,3];P2 = [4,4];figure;plot(P0(1),P0(2),"*"); hold on;plot(P1(1),P1(2),"*"); hold on;plot(P2(1),P2(2),"*"); hold on;ylim([0 7])xlim([0 5])legend("P0","P1","P2")% P0 is the center where the angle would beang = (180/pi)*(atan2(abs(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0))); % formula to get angle% ang = 63.439 deg
But when I took three coordinate values as the following then it gave me a strange angle value, which is probably the supplmentary angle at P0.
P1 = [-16.49,-17.69];P0 = [-25.83,-21.73];P2 = [-40.77,-18.10]figure;plot(P0(1),P0(2),"*"); hold on;plot(P1(1),P1(2),"*"); hold on;plot(P2(1),P2(2),"*"); hold on;legend("P0","P1","P2");ang = (180/pi)*(atan2(abs(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0)));% ang = 142.9526 deg ; seems like the supplementary angle at P0.
Why is it happening? Any clues?
I need to apply this formula to calculate angle over 100s of coordinates and but if this kind of non-uniformity would happen then I wouldn't be able to use it.
Any help would be appreciated!
Thank you.
I have also asked in the Matlab community at Mathworks:
https://in.mathworks.com/matlabcentral/answers/1793970-error-in-finding-the-angle-between-three-points-using-atan2
Beginner to excel here. I usually use Matlab for my calculations but for this particular project Excel has proven easier (until now).