atan2 and Cardan angles - Problem with sign











up vote
0
down vote

favorite












I'd like to get the three Cardan angles starting from the below matrix and by using the function atan2. The problem is that I get two conflicting results.



enter image description here



where $- pi/2 le beta le pi/2$.



If I consider the case $x>0$ in the above Wikipedia's webpage, I'll get (I call $R_{ij}$ the elements of the matrix):



$$ tan(gamma) = -frac{R_{31}}{R_{33}} $$



and I can use one of these two $operatorname {atan2}.$



Case 1: $x=R_{33}>0$



$$ gamma = operatorname {atan2}(-R_{31},R_{33}) = arctan(tan(gamma)) = gamma $$



if $R_{33}>0$.



Case 2: $x=-R_{33}>0$



$$ gamma = operatorname {atan2}(R_{31},-R_{33}) = arctan(tan(gamma)) = gamma $$



if $-R_{33}>0$.



How it is possible to get the same result the first time when $R_{33}>0$, the second time when $-R_{33}>0$?



Maybe I can pass from $tan$ to $operatorname {atan2}$ only when there is no sign before the ratio between the numerator and the denominator of the right term $tan(text {angle})=dfrac {text {numerator}}{text {denominator}}$?



Thank you so much in advance.










share|cite|improve this question




















  • 1




    As $cos beta>0$, you always have that $(cos γ,sinγ)sim (R_{33},-R_{31})$ so that always $γ=arg(R_{33}-iR_{31})=atan2(-R_{31},R_{33})$.
    – LutzL
    17 hours ago










  • Hello @LutzL, can you tell me why you wrote $(cos γ,sinγ)sim (R_{33},-R_{31})$ instead of $(cos γ,-sinγ)sim (R_{33},-R_{31})$ please?
    – Gennaro Arguzzi
    17 hours ago






  • 1




    Because there is only one sign to distribute. As I said, $cosβ>0$ and $(cosγ,sinγ)=(R_{33},−R_{31})/cosβ$. This defines the polar decomposition uniquely.
    – LutzL
    16 hours ago










  • @LutzL thank you for your extremely clear explanation.
    – Gennaro Arguzzi
    16 hours ago






  • 1




    1. So what do you find confusing here exactly? Why are you expecting different results in two chains of equalities that both start with $gamma$? As it is, it is unclear what you are asking. 2. How is $gamma$ defined, and what is its domain? You know that $arctan(tangamma)=gamma$ does not hold in general, right?
    – Federico Poloni
    16 hours ago

















up vote
0
down vote

favorite












I'd like to get the three Cardan angles starting from the below matrix and by using the function atan2. The problem is that I get two conflicting results.



enter image description here



where $- pi/2 le beta le pi/2$.



If I consider the case $x>0$ in the above Wikipedia's webpage, I'll get (I call $R_{ij}$ the elements of the matrix):



$$ tan(gamma) = -frac{R_{31}}{R_{33}} $$



and I can use one of these two $operatorname {atan2}.$



Case 1: $x=R_{33}>0$



$$ gamma = operatorname {atan2}(-R_{31},R_{33}) = arctan(tan(gamma)) = gamma $$



if $R_{33}>0$.



Case 2: $x=-R_{33}>0$



$$ gamma = operatorname {atan2}(R_{31},-R_{33}) = arctan(tan(gamma)) = gamma $$



if $-R_{33}>0$.



How it is possible to get the same result the first time when $R_{33}>0$, the second time when $-R_{33}>0$?



Maybe I can pass from $tan$ to $operatorname {atan2}$ only when there is no sign before the ratio between the numerator and the denominator of the right term $tan(text {angle})=dfrac {text {numerator}}{text {denominator}}$?



Thank you so much in advance.










share|cite|improve this question




















  • 1




    As $cos beta>0$, you always have that $(cos γ,sinγ)sim (R_{33},-R_{31})$ so that always $γ=arg(R_{33}-iR_{31})=atan2(-R_{31},R_{33})$.
    – LutzL
    17 hours ago










  • Hello @LutzL, can you tell me why you wrote $(cos γ,sinγ)sim (R_{33},-R_{31})$ instead of $(cos γ,-sinγ)sim (R_{33},-R_{31})$ please?
    – Gennaro Arguzzi
    17 hours ago






  • 1




    Because there is only one sign to distribute. As I said, $cosβ>0$ and $(cosγ,sinγ)=(R_{33},−R_{31})/cosβ$. This defines the polar decomposition uniquely.
    – LutzL
    16 hours ago










  • @LutzL thank you for your extremely clear explanation.
    – Gennaro Arguzzi
    16 hours ago






  • 1




    1. So what do you find confusing here exactly? Why are you expecting different results in two chains of equalities that both start with $gamma$? As it is, it is unclear what you are asking. 2. How is $gamma$ defined, and what is its domain? You know that $arctan(tangamma)=gamma$ does not hold in general, right?
    – Federico Poloni
    16 hours ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'd like to get the three Cardan angles starting from the below matrix and by using the function atan2. The problem is that I get two conflicting results.



enter image description here



where $- pi/2 le beta le pi/2$.



If I consider the case $x>0$ in the above Wikipedia's webpage, I'll get (I call $R_{ij}$ the elements of the matrix):



$$ tan(gamma) = -frac{R_{31}}{R_{33}} $$



and I can use one of these two $operatorname {atan2}.$



Case 1: $x=R_{33}>0$



$$ gamma = operatorname {atan2}(-R_{31},R_{33}) = arctan(tan(gamma)) = gamma $$



if $R_{33}>0$.



Case 2: $x=-R_{33}>0$



$$ gamma = operatorname {atan2}(R_{31},-R_{33}) = arctan(tan(gamma)) = gamma $$



if $-R_{33}>0$.



How it is possible to get the same result the first time when $R_{33}>0$, the second time when $-R_{33}>0$?



Maybe I can pass from $tan$ to $operatorname {atan2}$ only when there is no sign before the ratio between the numerator and the denominator of the right term $tan(text {angle})=dfrac {text {numerator}}{text {denominator}}$?



Thank you so much in advance.










share|cite|improve this question















I'd like to get the three Cardan angles starting from the below matrix and by using the function atan2. The problem is that I get two conflicting results.



enter image description here



where $- pi/2 le beta le pi/2$.



If I consider the case $x>0$ in the above Wikipedia's webpage, I'll get (I call $R_{ij}$ the elements of the matrix):



$$ tan(gamma) = -frac{R_{31}}{R_{33}} $$



and I can use one of these two $operatorname {atan2}.$



Case 1: $x=R_{33}>0$



$$ gamma = operatorname {atan2}(-R_{31},R_{33}) = arctan(tan(gamma)) = gamma $$



if $R_{33}>0$.



Case 2: $x=-R_{33}>0$



$$ gamma = operatorname {atan2}(R_{31},-R_{33}) = arctan(tan(gamma)) = gamma $$



if $-R_{33}>0$.



How it is possible to get the same result the first time when $R_{33}>0$, the second time when $-R_{33}>0$?



Maybe I can pass from $tan$ to $operatorname {atan2}$ only when there is no sign before the ratio between the numerator and the denominator of the right term $tan(text {angle})=dfrac {text {numerator}}{text {denominator}}$?



Thank you so much in advance.







trigonometry education classical-mechanics






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited 10 hours ago









bjcolby15

1,0901916




1,0901916










asked 17 hours ago









Gennaro Arguzzi

321313




321313








  • 1




    As $cos beta>0$, you always have that $(cos γ,sinγ)sim (R_{33},-R_{31})$ so that always $γ=arg(R_{33}-iR_{31})=atan2(-R_{31},R_{33})$.
    – LutzL
    17 hours ago










  • Hello @LutzL, can you tell me why you wrote $(cos γ,sinγ)sim (R_{33},-R_{31})$ instead of $(cos γ,-sinγ)sim (R_{33},-R_{31})$ please?
    – Gennaro Arguzzi
    17 hours ago






  • 1




    Because there is only one sign to distribute. As I said, $cosβ>0$ and $(cosγ,sinγ)=(R_{33},−R_{31})/cosβ$. This defines the polar decomposition uniquely.
    – LutzL
    16 hours ago










  • @LutzL thank you for your extremely clear explanation.
    – Gennaro Arguzzi
    16 hours ago






  • 1




    1. So what do you find confusing here exactly? Why are you expecting different results in two chains of equalities that both start with $gamma$? As it is, it is unclear what you are asking. 2. How is $gamma$ defined, and what is its domain? You know that $arctan(tangamma)=gamma$ does not hold in general, right?
    – Federico Poloni
    16 hours ago
















  • 1




    As $cos beta>0$, you always have that $(cos γ,sinγ)sim (R_{33},-R_{31})$ so that always $γ=arg(R_{33}-iR_{31})=atan2(-R_{31},R_{33})$.
    – LutzL
    17 hours ago










  • Hello @LutzL, can you tell me why you wrote $(cos γ,sinγ)sim (R_{33},-R_{31})$ instead of $(cos γ,-sinγ)sim (R_{33},-R_{31})$ please?
    – Gennaro Arguzzi
    17 hours ago






  • 1




    Because there is only one sign to distribute. As I said, $cosβ>0$ and $(cosγ,sinγ)=(R_{33},−R_{31})/cosβ$. This defines the polar decomposition uniquely.
    – LutzL
    16 hours ago










  • @LutzL thank you for your extremely clear explanation.
    – Gennaro Arguzzi
    16 hours ago






  • 1




    1. So what do you find confusing here exactly? Why are you expecting different results in two chains of equalities that both start with $gamma$? As it is, it is unclear what you are asking. 2. How is $gamma$ defined, and what is its domain? You know that $arctan(tangamma)=gamma$ does not hold in general, right?
    – Federico Poloni
    16 hours ago










1




1




As $cos beta>0$, you always have that $(cos γ,sinγ)sim (R_{33},-R_{31})$ so that always $γ=arg(R_{33}-iR_{31})=atan2(-R_{31},R_{33})$.
– LutzL
17 hours ago




As $cos beta>0$, you always have that $(cos γ,sinγ)sim (R_{33},-R_{31})$ so that always $γ=arg(R_{33}-iR_{31})=atan2(-R_{31},R_{33})$.
– LutzL
17 hours ago












Hello @LutzL, can you tell me why you wrote $(cos γ,sinγ)sim (R_{33},-R_{31})$ instead of $(cos γ,-sinγ)sim (R_{33},-R_{31})$ please?
– Gennaro Arguzzi
17 hours ago




Hello @LutzL, can you tell me why you wrote $(cos γ,sinγ)sim (R_{33},-R_{31})$ instead of $(cos γ,-sinγ)sim (R_{33},-R_{31})$ please?
– Gennaro Arguzzi
17 hours ago




1




1




Because there is only one sign to distribute. As I said, $cosβ>0$ and $(cosγ,sinγ)=(R_{33},−R_{31})/cosβ$. This defines the polar decomposition uniquely.
– LutzL
16 hours ago




Because there is only one sign to distribute. As I said, $cosβ>0$ and $(cosγ,sinγ)=(R_{33},−R_{31})/cosβ$. This defines the polar decomposition uniquely.
– LutzL
16 hours ago












@LutzL thank you for your extremely clear explanation.
– Gennaro Arguzzi
16 hours ago




@LutzL thank you for your extremely clear explanation.
– Gennaro Arguzzi
16 hours ago




1




1




1. So what do you find confusing here exactly? Why are you expecting different results in two chains of equalities that both start with $gamma$? As it is, it is unclear what you are asking. 2. How is $gamma$ defined, and what is its domain? You know that $arctan(tangamma)=gamma$ does not hold in general, right?
– Federico Poloni
16 hours ago






1. So what do you find confusing here exactly? Why are you expecting different results in two chains of equalities that both start with $gamma$? As it is, it is unclear what you are asking. 2. How is $gamma$ defined, and what is its domain? You know that $arctan(tangamma)=gamma$ does not hold in general, right?
– Federico Poloni
16 hours ago












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The ratio $frac{sin gamma}{cosgamma}$ does not specify an angle $-pi < gamma leq pi$ uniquely, but only up to $pi$; to specify it, you need two coordinates $x,y$, not both zero, through which the variable side of the angle passes: that's the whole idea behind atan2 and you should make sure you are familiar with it before tackling these computations.



In your case, you have restricted to $-fracpi2 < gamma < fracpi2$, which means that your angle is in the right half-plane, so these coordinates have $x>0$. Focus on the first equal sign in each of those two alternative computations: only one of them is correct, the one with $cosgamma > 0$. To know which one it is, you will have to know the sign of $cos beta$ as well.






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: 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%2f2997004%2fatan2-and-cardan-angles-problem-with-sign%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
    1
    down vote



    accepted










    The ratio $frac{sin gamma}{cosgamma}$ does not specify an angle $-pi < gamma leq pi$ uniquely, but only up to $pi$; to specify it, you need two coordinates $x,y$, not both zero, through which the variable side of the angle passes: that's the whole idea behind atan2 and you should make sure you are familiar with it before tackling these computations.



    In your case, you have restricted to $-fracpi2 < gamma < fracpi2$, which means that your angle is in the right half-plane, so these coordinates have $x>0$. Focus on the first equal sign in each of those two alternative computations: only one of them is correct, the one with $cosgamma > 0$. To know which one it is, you will have to know the sign of $cos beta$ as well.






    share|cite|improve this answer

























      up vote
      1
      down vote



      accepted










      The ratio $frac{sin gamma}{cosgamma}$ does not specify an angle $-pi < gamma leq pi$ uniquely, but only up to $pi$; to specify it, you need two coordinates $x,y$, not both zero, through which the variable side of the angle passes: that's the whole idea behind atan2 and you should make sure you are familiar with it before tackling these computations.



      In your case, you have restricted to $-fracpi2 < gamma < fracpi2$, which means that your angle is in the right half-plane, so these coordinates have $x>0$. Focus on the first equal sign in each of those two alternative computations: only one of them is correct, the one with $cosgamma > 0$. To know which one it is, you will have to know the sign of $cos beta$ as well.






      share|cite|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        The ratio $frac{sin gamma}{cosgamma}$ does not specify an angle $-pi < gamma leq pi$ uniquely, but only up to $pi$; to specify it, you need two coordinates $x,y$, not both zero, through which the variable side of the angle passes: that's the whole idea behind atan2 and you should make sure you are familiar with it before tackling these computations.



        In your case, you have restricted to $-fracpi2 < gamma < fracpi2$, which means that your angle is in the right half-plane, so these coordinates have $x>0$. Focus on the first equal sign in each of those two alternative computations: only one of them is correct, the one with $cosgamma > 0$. To know which one it is, you will have to know the sign of $cos beta$ as well.






        share|cite|improve this answer












        The ratio $frac{sin gamma}{cosgamma}$ does not specify an angle $-pi < gamma leq pi$ uniquely, but only up to $pi$; to specify it, you need two coordinates $x,y$, not both zero, through which the variable side of the angle passes: that's the whole idea behind atan2 and you should make sure you are familiar with it before tackling these computations.



        In your case, you have restricted to $-fracpi2 < gamma < fracpi2$, which means that your angle is in the right half-plane, so these coordinates have $x>0$. Focus on the first equal sign in each of those two alternative computations: only one of them is correct, the one with $cosgamma > 0$. To know which one it is, you will have to know the sign of $cos beta$ as well.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered 3 hours ago









        Federico Poloni

        2,4441325




        2,4441325






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2997004%2fatan2-and-cardan-angles-problem-with-sign%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Plaza Victoria

            In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

            How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...