How to convert components into an angle directly (for vectors)?

1.7k Views Asked by At

Let us say we have a vector with $x$-component $-2$, and $y$-component $-1$. We have the equation:

$$\tan\theta=\frac{-1}{-2}$$

So if we take the inverse of $\tan$ of $\frac12$ we get $26.565^\circ$. The problem is this is wrong, it's $206.565^\circ$. The problem is apparent; the equation above has multiple solutions. The inverse of $\tan$ occasionally gives us the wrong angle. (Another way to understand the problem is that the magnitude satisfies $c^2 = (-2)^2 + (-1)^2$, which has two solutions, one of which makes $26.565^\circ$ correct).

Of course, you can draw pictures to solve this and figure out which angle is correct. My question is, is there a more direct way to find the angle? Ideally, it should involve any decision making or conditionals, it should be a direct calculation.

I know that what a "direct calculation" constitutes is technically subjective.

4

There are 4 best solutions below

0
On

The formula $$ \theta=\arctan\left(\frac yx\right)\tag{1} $$ assumes that $x\gt0$. If $x\lt0$, then add or subtract $180^\circ$ as desired.

A formula I use is $$ \theta=2\arctan\left(\frac{y}{x+\sqrt{x^2+y^2}}\right)\tag{2} $$ Just as $(1)$ divides by $0$ when $x=0$, $(2)$ divides by $0$ when $x\le0$ and $y=0$; that is, when $(x,y)$ is on the negative $x$-axis, where $\theta=180^\circ$.

0
On

When you have an equation, in general, like $$\tan \theta = l = \tan \alpha \,\ (\text{say})$$

then the general solution of $\theta$ is given by $$\theta = n\pi + \alpha = n\pi + \arctan l \,\ , \,\ n \in \mathbb{N}$$

Now since in this case, it is mentioned that both the $x,y$ components are negative, then obviously it lies in the third quadrant and now the general solution of $\theta$ is given by $$\theta = (2n-1)\pi + \alpha = (2n-1)\pi + \arctan l \,\ , \,\ n \in \mathbb{N}$$

As in this case and in majority problems, the principal value of $\theta$ is asked for and as we know, for the principal value of $\theta$, $-\pi<\theta \le \pi$.

So you get the answer as mentioned in the problem.

Hope this helps in clearing your doubts.

0
On

If we restrict this problem to only 2-dimensions, we can compute this directly using the atan2 function. The range is $\left(-\frac{\pi \:}{2},\:\frac{\pi \:}{2}\right)$, but you can easily adapt this for the range that you desire.

5
On

The problem is that you lose information when you pass from $(x,y)$ to $y/x$. Knowing the first determines the second, but the process is not reversible.

You need a function like the C library function atan2(x,y) which can choose the proper angle because the coordinates are passed in properly. In other words, you must make a decision or use a conditional expression, even if it is hidden in some sort of boolean expression.