Error in finding the angle between three points using atan2
Afficher commentaires plus anciens
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 be
ang = (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.
Réponse acceptée
Plus de réponses (0)
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!
