Why subtract $pi$ in the definition of atan2?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Looking here the definition of the atan2 function is as follows:



$$operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0text and ygeq 0,\
arctan(frac yx)-pi & textif x<0text and y<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text andy<0,\
textundefined & textif x=0text and y=0.
endcases$$



This looks wrong to me. Or at least, not wrong but rather there seems to be a small issue with it.



My Reasoning



I was trying to figure out a function (like $atan2$) that would solve the problem of the $arctan$ function. This is because I am writing a Python function to find the complex argument of a complex number, given real and imaginary part. Here is my reasoning:



Given a non-negative tangent value, this is mapped by the arctan only in the range $left[0, fracpi2right)$.



Given a non-positive tangent value, this is mapped by the arctan only in the range $left[0, -fracpi2right)$.



However, given a non-negative tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is an angle $theta in left[0, fracpi2right)$

  • $theta + pi$ which is a diametrically opposite angle in the third quadrant, that is $left[pi, -frac3pi2right)$

Similarly, given a non-positive tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is a negative angle in $theta inleft[0, -fracpi2right)$

  • $theta + pi$ which is diametrically opposite angle in the second quadrant, that is $left(fracpi2, piright]$

Thus, the definition of $atan2$ that I would use, would be:



$
operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text and y<0,\
textundefined & textif x=0text and y=0.
endcases

$



Why does the Wikipedia definition subtract $pi$ when we are in the third quadrant ($x<0$ and $y<0$)? If we do this, we end up with a negative angle! Yes sure, the negative angle would have the same sine, cosine and tangent of the angle obtained by summing $pi$, but why bother?







share|cite|improve this question





















  • You said it, why bother ?
    – Yves Daoust
    Jul 26 at 11:50










  • Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end
    – Euler_Salter
    Jul 26 at 11:53










  • You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
    – Yves Daoust
    Jul 26 at 11:55






  • 2




    The principal branch has $-pi < arctan2(x)le pi$. Your definition doesn't satisfy that condition.
    – Mark Viola
    Jul 26 at 11:59











  • @MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2pi$ multiples! Could you please write an answer for future reference?
    – Euler_Salter
    Jul 26 at 12:05














up vote
1
down vote

favorite












Looking here the definition of the atan2 function is as follows:



$$operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0text and ygeq 0,\
arctan(frac yx)-pi & textif x<0text and y<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text andy<0,\
textundefined & textif x=0text and y=0.
endcases$$



This looks wrong to me. Or at least, not wrong but rather there seems to be a small issue with it.



My Reasoning



I was trying to figure out a function (like $atan2$) that would solve the problem of the $arctan$ function. This is because I am writing a Python function to find the complex argument of a complex number, given real and imaginary part. Here is my reasoning:



Given a non-negative tangent value, this is mapped by the arctan only in the range $left[0, fracpi2right)$.



Given a non-positive tangent value, this is mapped by the arctan only in the range $left[0, -fracpi2right)$.



However, given a non-negative tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is an angle $theta in left[0, fracpi2right)$

  • $theta + pi$ which is a diametrically opposite angle in the third quadrant, that is $left[pi, -frac3pi2right)$

Similarly, given a non-positive tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is a negative angle in $theta inleft[0, -fracpi2right)$

  • $theta + pi$ which is diametrically opposite angle in the second quadrant, that is $left(fracpi2, piright]$

Thus, the definition of $atan2$ that I would use, would be:



$
operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text and y<0,\
textundefined & textif x=0text and y=0.
endcases

$



Why does the Wikipedia definition subtract $pi$ when we are in the third quadrant ($x<0$ and $y<0$)? If we do this, we end up with a negative angle! Yes sure, the negative angle would have the same sine, cosine and tangent of the angle obtained by summing $pi$, but why bother?







share|cite|improve this question





















  • You said it, why bother ?
    – Yves Daoust
    Jul 26 at 11:50










  • Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end
    – Euler_Salter
    Jul 26 at 11:53










  • You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
    – Yves Daoust
    Jul 26 at 11:55






  • 2




    The principal branch has $-pi < arctan2(x)le pi$. Your definition doesn't satisfy that condition.
    – Mark Viola
    Jul 26 at 11:59











  • @MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2pi$ multiples! Could you please write an answer for future reference?
    – Euler_Salter
    Jul 26 at 12:05












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Looking here the definition of the atan2 function is as follows:



$$operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0text and ygeq 0,\
arctan(frac yx)-pi & textif x<0text and y<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text andy<0,\
textundefined & textif x=0text and y=0.
endcases$$



This looks wrong to me. Or at least, not wrong but rather there seems to be a small issue with it.



My Reasoning



I was trying to figure out a function (like $atan2$) that would solve the problem of the $arctan$ function. This is because I am writing a Python function to find the complex argument of a complex number, given real and imaginary part. Here is my reasoning:



Given a non-negative tangent value, this is mapped by the arctan only in the range $left[0, fracpi2right)$.



Given a non-positive tangent value, this is mapped by the arctan only in the range $left[0, -fracpi2right)$.



However, given a non-negative tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is an angle $theta in left[0, fracpi2right)$

  • $theta + pi$ which is a diametrically opposite angle in the third quadrant, that is $left[pi, -frac3pi2right)$

Similarly, given a non-positive tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is a negative angle in $theta inleft[0, -fracpi2right)$

  • $theta + pi$ which is diametrically opposite angle in the second quadrant, that is $left(fracpi2, piright]$

Thus, the definition of $atan2$ that I would use, would be:



$
operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text and y<0,\
textundefined & textif x=0text and y=0.
endcases

$



Why does the Wikipedia definition subtract $pi$ when we are in the third quadrant ($x<0$ and $y<0$)? If we do this, we end up with a negative angle! Yes sure, the negative angle would have the same sine, cosine and tangent of the angle obtained by summing $pi$, but why bother?







share|cite|improve this question













Looking here the definition of the atan2 function is as follows:



$$operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0text and ygeq 0,\
arctan(frac yx)-pi & textif x<0text and y<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text andy<0,\
textundefined & textif x=0text and y=0.
endcases$$



This looks wrong to me. Or at least, not wrong but rather there seems to be a small issue with it.



My Reasoning



I was trying to figure out a function (like $atan2$) that would solve the problem of the $arctan$ function. This is because I am writing a Python function to find the complex argument of a complex number, given real and imaginary part. Here is my reasoning:



Given a non-negative tangent value, this is mapped by the arctan only in the range $left[0, fracpi2right)$.



Given a non-positive tangent value, this is mapped by the arctan only in the range $left[0, -fracpi2right)$.



However, given a non-negative tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is an angle $theta in left[0, fracpi2right)$

  • $theta + pi$ which is a diametrically opposite angle in the third quadrant, that is $left[pi, -frac3pi2right)$

Similarly, given a non-positive tangent value, there are two angles that could have that tangent value:



  • $arctan(tan(theta))$ which is a negative angle in $theta inleft[0, -fracpi2right)$

  • $theta + pi$ which is diametrically opposite angle in the second quadrant, that is $left(fracpi2, piright]$

Thus, the definition of $atan2$ that I would use, would be:



$
operatorname atan2 (y,x)=
begincases
arctan(frac yx) & textif x>0,\
arctan(frac yx)+pi & textif x<0,\
+frac pi2 & textif x=0text and y>0,\
-frac pi 2 & textif x=0text and y<0,\
textundefined & textif x=0text and y=0.
endcases

$



Why does the Wikipedia definition subtract $pi$ when we are in the third quadrant ($x<0$ and $y<0$)? If we do this, we end up with a negative angle! Yes sure, the negative angle would have the same sine, cosine and tangent of the angle obtained by summing $pi$, but why bother?









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited Jul 26 at 11:47
























asked Jul 26 at 11:43









Euler_Salter

2,0071331




2,0071331











  • You said it, why bother ?
    – Yves Daoust
    Jul 26 at 11:50










  • Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end
    – Euler_Salter
    Jul 26 at 11:53










  • You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
    – Yves Daoust
    Jul 26 at 11:55






  • 2




    The principal branch has $-pi < arctan2(x)le pi$. Your definition doesn't satisfy that condition.
    – Mark Viola
    Jul 26 at 11:59











  • @MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2pi$ multiples! Could you please write an answer for future reference?
    – Euler_Salter
    Jul 26 at 12:05
















  • You said it, why bother ?
    – Yves Daoust
    Jul 26 at 11:50










  • Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end
    – Euler_Salter
    Jul 26 at 11:53










  • You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
    – Yves Daoust
    Jul 26 at 11:55






  • 2




    The principal branch has $-pi < arctan2(x)le pi$. Your definition doesn't satisfy that condition.
    – Mark Viola
    Jul 26 at 11:59











  • @MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2pi$ multiples! Could you please write an answer for future reference?
    – Euler_Salter
    Jul 26 at 12:05















You said it, why bother ?
– Yves Daoust
Jul 26 at 11:50




You said it, why bother ?
– Yves Daoust
Jul 26 at 11:50












Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end
– Euler_Salter
Jul 26 at 11:53




Because in my way the definition is much more succinct, and I do not have to re-convert the angle at the end
– Euler_Salter
Jul 26 at 11:53












You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
– Yves Daoust
Jul 26 at 11:55




You reconvert the angle because you want to adopt a different convention, you can only blame yourself. The "standard" convention is not worse than another.
– Yves Daoust
Jul 26 at 11:55




2




2




The principal branch has $-pi < arctan2(x)le pi$. Your definition doesn't satisfy that condition.
– Mark Viola
Jul 26 at 11:59





The principal branch has $-pi < arctan2(x)le pi$. Your definition doesn't satisfy that condition.
– Mark Viola
Jul 26 at 11:59













@MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2pi$ multiples! Could you please write an answer for future reference?
– Euler_Salter
Jul 26 at 12:05




@MarkViola That! That is what explains everything! The principal branch of the complex number is defined within that interval because otherwise we could have multiple ones just by adding $2pi$ multiples! Could you please write an answer for future reference?
– Euler_Salter
Jul 26 at 12:05










1 Answer
1






active

oldest

votes

















up vote
2
down vote













For consistency, the $textatan_2$ values are defined in a range that equals a full period.



The usual choice is $(-pi,pi]$, but this is arbitrary and inessential, provided you know it.



What really matters is that when taking the cosine and sine, the original signs are restored.




Whatever the convention, computing with angles is often tricky.






share|cite|improve this answer























    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',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    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%2f2863341%2fwhy-subtract-pi-in-the-definition-of-atan2%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    For consistency, the $textatan_2$ values are defined in a range that equals a full period.



    The usual choice is $(-pi,pi]$, but this is arbitrary and inessential, provided you know it.



    What really matters is that when taking the cosine and sine, the original signs are restored.




    Whatever the convention, computing with angles is often tricky.






    share|cite|improve this answer



























      up vote
      2
      down vote













      For consistency, the $textatan_2$ values are defined in a range that equals a full period.



      The usual choice is $(-pi,pi]$, but this is arbitrary and inessential, provided you know it.



      What really matters is that when taking the cosine and sine, the original signs are restored.




      Whatever the convention, computing with angles is often tricky.






      share|cite|improve this answer

























        up vote
        2
        down vote










        up vote
        2
        down vote









        For consistency, the $textatan_2$ values are defined in a range that equals a full period.



        The usual choice is $(-pi,pi]$, but this is arbitrary and inessential, provided you know it.



        What really matters is that when taking the cosine and sine, the original signs are restored.




        Whatever the convention, computing with angles is often tricky.






        share|cite|improve this answer















        For consistency, the $textatan_2$ values are defined in a range that equals a full period.



        The usual choice is $(-pi,pi]$, but this is arbitrary and inessential, provided you know it.



        What really matters is that when taking the cosine and sine, the original signs are restored.




        Whatever the convention, computing with angles is often tricky.







        share|cite|improve this answer















        share|cite|improve this answer



        share|cite|improve this answer








        edited Jul 26 at 11:59


























        answered Jul 26 at 11:54









        Yves Daoust

        111k665203




        111k665203






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2863341%2fwhy-subtract-pi-in-the-definition-of-atan2%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What is the equation of a 3D cone with generalised tilt?

            Color the edges and diagonals of a regular polygon

            Relationship between determinant of matrix and determinant of adjoint?