Usually when people discuss getting the polar form of a vector $v$, they present the following two formulas:

$$\text{Magnitude}(v) = \sqrt{x^2 + y^2}$$

$$\text{Angle}(v) = \arctan \left(\frac{y}{x} \right)$$

$$ \text{ Where } \space v = \begin{bmatrix} x \\ y \end{bmatrix}$$

I believe that this formula for the angle is only partially true. I think a better and more complete formula for the angle should be:

$$ \text{Angle}(v) = \begin{cases} \arctan \left(\frac{y}{x} \right) &; \space x \gt 0 \\ \pi +\arctan \left(\frac{y}{x} \right) &; \space x \lt 0 \\ {\begin{cases} \operatorname{sign}(y) \frac{\pi}{2} &; y \neq 0 \\ \text{undefined} &; \space y = 0 \end{cases}} &; x = 0 \end{cases} $$

Is there some sort of way to simplify this or to better express this, or is this it?

  • 4
    $\begingroup$ The "atan2" function was devised to help with this. $\endgroup$ – Blue Jan 20 at 14:59
  • 2
    $\begingroup$ BTW: You can see atan2 being used in the "Converting between polar and Cartesian coordinates" section of Wikipedia's "polar coordinate system" entry. Who are these people you've been talking-to who "usually" just use arctan? $\endgroup$ – Blue Jan 20 at 15:06
  • 1
    $\begingroup$ That's unfortunate. :/ $\endgroup$ – Blue Jan 20 at 15:13
  • 1
    $\begingroup$ @Blue Thank you for your sympathy. :) $\endgroup$ – Gustav Jan 20 at 15:16
  • 3
    $\begingroup$ I'll note that the computer algebra Mathematica uses a "smart" ArcTan function: when fed just one argument, it gives the regular inverse-tangent; when given both $x$ and $y$ arguments, it gives the quadrant-savvy version of the angle (equivalent to atan2). $\endgroup$ – Blue Jan 20 at 15:20

If you want an answer in form of a mathematical function definition, using only functions that were in common use in undergraduate instruction fifty years ago, I do not think you can do much better than the excellent answer by Rhys Hughes. As noted in the answer, this is how mathematicians often define a function equivalent to yours in textbooks. The only detail you might want to add is something to deal with the case $x = y = 0.$

Note that the formulas in that answer do not tell you how to find $\theta,$ but they do uniquely identify the output of the function for any possible input. There is always some value of $\theta$ that will satisfy both equations when $x^2 + y^2 \neq 0,$ and there will never be more than one value of $\theta$ that satisfies both equations.

If you want a formula to compute the angle using only functions that were in common use in undergraduate instruction fifty years ago, I think the formula you wrote is close to the best you can get, though I would handle one or two cases a bit differently.

If you want a nice way to represent your function in other formulas, you can borrow the two-parameter arc tangent function that is defined in many software packages. That is, define a function $\operatorname{atan2}(y, x)$ whose value is the angle of the vector $\begin{bmatrix} x \\ y \end{bmatrix}.$ You can define $\operatorname{atan2}(y, x)$ either in the style of the complex analysis textbooks described in the other answer, or you can define it in your style:

$$ \operatorname{atan2}(y, x) = \begin{cases} \arctan\left(\frac yx\right) & x \gt 0 \\ \arctan\left(\frac yx\right) + \pi \quad & x \lt 0, \ y \geq 0 \\ \arctan\left(\frac yx\right) - \pi \quad & x \lt 0, \ y < 0 \\ \frac\pi2 & x = 0,\ y > 0 \\ -\frac\pi2 & x = 0,\ y < 0 \\ \text{undefined} & x = 0,\ y = 0. \end{cases} $$

When this is implemented in software I think the "undefined" case usually returns $0.$

If you have to write formulas involving the direction angles of several two-dimensional vectors in terms of their components, then you might find the notation $\operatorname{atan2}(y, x)$ convenient.

  • $\begingroup$ @Gustav Wow! I mean wow squared. You complain that "they" leave a little bit for you to figure out instead of giving you exactly what you want on a silver platter, then you speculate this is because they are lazy? Wow. (This is an example of what they mean by "irony". If you visit the_internet.com you can apply for a refund of the monry you paid...) $\endgroup$ – David C. Ullrich Jan 20 at 16:29
  • $\begingroup$ @Gustav Not frustrated at all, more amused. $\endgroup$ – David C. Ullrich Jan 20 at 16:36
  • $\begingroup$ @Gustav I understood the question. And I have no problem with anything you said about the answer - my comment had to do with you complaining about him being lazy. (Do you know what the word "irony" means?) $\endgroup$ – David C. Ullrich Jan 20 at 16:45
  • 1
    $\begingroup$ No problem; I've deleted earlier comments. $\endgroup$ – David K Jan 20 at 17:12
  • 1
    $\begingroup$ @David C. Ullrich. Could you also remove your previous comments as they no longer serve any purpose? $\endgroup$ – Gustav Jan 20 at 17:20

This looks very similar to complex numbers, where $\text{Magnitude}(v)$ is displayed by $|v|$ and $\text{Angle}(v)$ is written $\text{arg}(v)$. We have that $\arg(v)$ is the unique angle $\in (-\pi, \pi]$ where:

$$\cos\theta =\frac{x}{|v|}=\frac{x}{\sqrt{x^2+y^2}}$$ and $$\sin\theta=\frac{y}{|v|}=\frac{y}{\sqrt{x^2+y^2}}$$

  • $\begingroup$ When working with only arctan, if we look at its graph, we can clearly see that it only gives values in the interval [$\frac{-\pi}{2}$ , $\frac{\pi}{2}$]. This only covers the first and fourth quadrants. So, in order to access the second and third quadrants, we need another definition. On top of that we need a definition for when the denomination in the usual definition would be zero, etc. $\endgroup$ – Gustav Jan 20 at 15:22
  • 1
    $\begingroup$ When the denominator equals to zero, the 2-norm or magnitude of the vector is 0 anyway. In other words, the 0 vector has no angle (Linear Algebra tells us that 0 is in the null space of any system fully described by the $R^2$). $\endgroup$ – Joel Biffin Jan 20 at 15:52
  • $\begingroup$ @Joel When the denominator is zero, only one of the components is zero, not both. So no, the magnitude is not zero. $\endgroup$ – Gustav Jan 20 at 15:58
  • $\begingroup$ @Gustav you literally called $\sqrt{x^2+y^2}$ the magnitude in your question! $\endgroup$ – Rhys Hughes Jan 20 at 16:01
  • $\begingroup$ 2 comments back, I accidentally wrote denomination instead of denominator. With this I mean the value of x. Sorry about that. $\endgroup$ – Gustav Jan 20 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.