How do we really get the angle of a vector from the components?












4












$begingroup$


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?










share|cite|improve this question











$endgroup$








  • 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


















4












$begingroup$


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?










share|cite|improve this question











$endgroup$








  • 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
















4












4








4


1



$begingroup$


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?










share|cite|improve this question











$endgroup$




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?







trigonometry vectors






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Jan 20 at 15:12









Bernard

121k740116




121k740116










asked Jan 20 at 14:56









GustavGustav

1469




1469








  • 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
















  • 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










4




4




$begingroup$
The "atan2" function was devised to help with this.
$endgroup$
– Blue
Jan 20 at 14:59




$begingroup$
The "atan2" function was devised to help with this.
$endgroup$
– Blue
Jan 20 at 14:59




2




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




$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




1




$begingroup$
That's unfortunate. :/
$endgroup$
– Blue
Jan 20 at 15:13




$begingroup$
That's unfortunate. :/
$endgroup$
– Blue
Jan 20 at 15:13




1




1




$begingroup$
@Blue Thank you for your sympathy. :)
$endgroup$
– Gustav
Jan 20 at 15:16




$begingroup$
@Blue Thank you for your sympathy. :)
$endgroup$
– Gustav
Jan 20 at 15:16




3




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






$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












2 Answers
2






active

oldest

votes


















7












$begingroup$

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}
arctanleft(frac yxright) & x gt 0 \
arctanleft(frac yxright) + pi quad & x lt 0, y geq 0 \
arctanleft(frac yxright) - pi quad & x lt 0, y < 0 \
fracpi2 & x = 0, y > 0 \
-fracpi2 & 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.






share|cite|improve this answer









$endgroup$













  • $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





















4












$begingroup$

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:



$$costheta =frac{x}{|v|}=frac{x}{sqrt{x^2+y^2}}$$
and
$$sintheta=frac{y}{|v|}=frac{y}{sqrt{x^2+y^2}}$$






share|cite|improve this answer









$endgroup$













  • $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





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3080680%2fhow-do-we-really-get-the-angle-of-a-vector-from-the-components%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









7












$begingroup$

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}
arctanleft(frac yxright) & x gt 0 \
arctanleft(frac yxright) + pi quad & x lt 0, y geq 0 \
arctanleft(frac yxright) - pi quad & x lt 0, y < 0 \
fracpi2 & x = 0, y > 0 \
-fracpi2 & 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.






share|cite|improve this answer









$endgroup$













  • $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


















7












$begingroup$

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}
arctanleft(frac yxright) & x gt 0 \
arctanleft(frac yxright) + pi quad & x lt 0, y geq 0 \
arctanleft(frac yxright) - pi quad & x lt 0, y < 0 \
fracpi2 & x = 0, y > 0 \
-fracpi2 & 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.






share|cite|improve this answer









$endgroup$













  • $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
















7












7








7





$begingroup$

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}
arctanleft(frac yxright) & x gt 0 \
arctanleft(frac yxright) + pi quad & x lt 0, y geq 0 \
arctanleft(frac yxright) - pi quad & x lt 0, y < 0 \
fracpi2 & x = 0, y > 0 \
-fracpi2 & 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.






share|cite|improve this answer









$endgroup$



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}
arctanleft(frac yxright) & x gt 0 \
arctanleft(frac yxright) + pi quad & x lt 0, y geq 0 \
arctanleft(frac yxright) - pi quad & x lt 0, y < 0 \
fracpi2 & x = 0, y > 0 \
-fracpi2 & 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.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Jan 20 at 16:01









David KDavid K

54.5k343120




54.5k343120












  • $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




















  • $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


















$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 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 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






$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




1




$begingroup$
No problem; I've deleted earlier comments.
$endgroup$
– David K
Jan 20 at 17:12




$begingroup$
No problem; I've deleted earlier comments.
$endgroup$
– David K
Jan 20 at 17:12




1




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






$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













4












$begingroup$

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:



$$costheta =frac{x}{|v|}=frac{x}{sqrt{x^2+y^2}}$$
and
$$sintheta=frac{y}{|v|}=frac{y}{sqrt{x^2+y^2}}$$






share|cite|improve this answer









$endgroup$













  • $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
















4












$begingroup$

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:



$$costheta =frac{x}{|v|}=frac{x}{sqrt{x^2+y^2}}$$
and
$$sintheta=frac{y}{|v|}=frac{y}{sqrt{x^2+y^2}}$$






share|cite|improve this answer









$endgroup$













  • $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














4












4








4





$begingroup$

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:



$$costheta =frac{x}{|v|}=frac{x}{sqrt{x^2+y^2}}$$
and
$$sintheta=frac{y}{|v|}=frac{y}{sqrt{x^2+y^2}}$$






share|cite|improve this answer









$endgroup$



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:



$$costheta =frac{x}{|v|}=frac{x}{sqrt{x^2+y^2}}$$
and
$$sintheta=frac{y}{|v|}=frac{y}{sqrt{x^2+y^2}}$$







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Jan 20 at 15:06









Rhys HughesRhys Hughes

6,7801530




6,7801530












  • $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


















  • $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
















$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






$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




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$
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$
@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$
@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




$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


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3080680%2fhow-do-we-really-get-the-angle-of-a-vector-from-the-components%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mario Kart Wii

What does “Dominus providebit” mean?

Antonio Litta Visconti Arese