Mathamatically deduce angle of vector for two values of Tangent

43 Views Asked by At

I have a rather simple requirement. I wish to find the angle of resultant vector with respect to x-axis, which I assume to be zero degrees. The problem I am facing is that, I want my mathematical formula to provide me the correct angle from the two values of inverse tangent. The method I am using are as follows:

Assuming two vectors A and B, which are at α and β from x-axis.

  1. Resolve A and B to Ax, Ay, Bx, and By. $$Ax=A\cos \alpha, Ay=\sin \alpha$$ Similarly for Bx and By.
  2. Resolve to find resultant: $$Rx=Ax+Bx, Ry=Ay+By$$ and $$R=\sqrt(Rx^2+Ry^2)$$
  3. Resolve the angle $$\gamma = \arctan ((Ay+By)/(Ax+Bx))$$ Here in lies my problem. Assuming $$A=200,B=100,\alpha = 45, \beta=225$$ I get two values for arctan 45 & 225.

I want a mathematical formula that will automatically produce the correct number in this case 225. The above approach works correctly if angles are less than 180 but not otherwise.

1

There are 1 best solutions below

0
On BEST ANSWER

The atan2(y,x) function is an enhanced version of arctangent which does exactly what you desire. You may familiarize yourself with the piecewise definition here.