I am trying to implement a script to analyze some of my data. I have position information for three points (p1,p2,p3). I would like to find the angular displacement of point p3 from the vector p1p2, as in this picture:
p3a, p3b, p3c, p3d show possible relative positions for p3. As shown, I would like the sign of the output angle to describe its relative position to vector p1p2.
The code I am using is as follows (adapted to the diagram):
v1 = p2 - p1;
x1 = v1(1);
y1 = v1(2);
v2 = p1 - p3;
x2 = v2(1);
y2 = v2(2);
angle = atan2d(x1*y2-y1*2,x1*x2+y1*y2);
This works as desired when p3 is at p3a, giving a negative angle of the right size (-77 degrees). However, when p3 is at p3d, it outputs a large positive angle (+150 degrees), as opposed to