How to find angle of rotation given the source point and x-coordinate of destination point?

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











up vote
0
down vote

favorite












Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
$$begincases
x' = x cos a - y sin a \
y' = x sin a + y cos a \
endcases$$



However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.







share|cite|improve this question

























    up vote
    0
    down vote

    favorite












    Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
    $$begincases
    x' = x cos a - y sin a \
    y' = x sin a + y cos a \
    endcases$$



    However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.







    share|cite|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
      $$begincases
      x' = x cos a - y sin a \
      y' = x sin a + y cos a \
      endcases$$



      However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.







      share|cite|improve this question













      Just for the sake of simplicity, assume that the centre of rotation is $(0, 0)$. I know that I can find the destination point $(x', y')$ given angle of rotation $a$ and source point $(x, y)$ using
      $$begincases
      x' = x cos a - y sin a \
      y' = x sin a + y cos a \
      endcases$$



      However, I want to ask how can I find the angle of rotation $a$ given the source point $(x, y)$ and only the x-coordination of the destination point $x'$? The y-coordinate of destination point $y'$ would be according to the angle of rotation $a$ that we get. I am having trouble trying to solve the above equations for the desired value because we don't have exact value of $y'$. It would be great if someone could help. Thanks.









      share|cite|improve this question












      share|cite|improve this question




      share|cite|improve this question








      edited Aug 2 at 13:25
























      asked Aug 2 at 12:58









      Newbie

      184




      184




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          First we replace $sin a$ with $sqrt1-cos^2a$:
          $$x' = x cos a - y sqrt1-cos^2 a$$



          Then we eliminate the square root by isolating it and squaring:
          $$y sqrt1-cos^2 a = x cos a - x'$$
          $$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$



          This can now be rewritten as a quadric in $cos a$:
          $$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
          $$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$



          It can be solve using the "$p$-$q$-formula":
          $$
          cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
          = fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
          $$



          A couple of notes:



          1. The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.

          2. When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.





          share|cite|improve this answer





















          • Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
            – Newbie
            Aug 2 at 16:00










          • Oh, you are right.
            – md2perpe
            Aug 2 at 16:03

















          up vote
          2
          down vote













          Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if you’re coding this, there’s likely a two-argument form of the arctangent function available (often called something like ATAN2) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.






          share|cite|improve this answer























          • This is the approach I would have taken. Plus one.
            – Lubin
            Aug 2 at 22:36










          • Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
            – Newbie
            Aug 3 at 1:22











          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%2f2870039%2fhow-to-find-angle-of-rotation-given-the-source-point-and-x-coordinate-of-destina%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          First we replace $sin a$ with $sqrt1-cos^2a$:
          $$x' = x cos a - y sqrt1-cos^2 a$$



          Then we eliminate the square root by isolating it and squaring:
          $$y sqrt1-cos^2 a = x cos a - x'$$
          $$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$



          This can now be rewritten as a quadric in $cos a$:
          $$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
          $$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$



          It can be solve using the "$p$-$q$-formula":
          $$
          cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
          = fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
          $$



          A couple of notes:



          1. The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.

          2. When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.





          share|cite|improve this answer





















          • Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
            – Newbie
            Aug 2 at 16:00










          • Oh, you are right.
            – md2perpe
            Aug 2 at 16:03














          up vote
          1
          down vote



          accepted










          First we replace $sin a$ with $sqrt1-cos^2a$:
          $$x' = x cos a - y sqrt1-cos^2 a$$



          Then we eliminate the square root by isolating it and squaring:
          $$y sqrt1-cos^2 a = x cos a - x'$$
          $$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$



          This can now be rewritten as a quadric in $cos a$:
          $$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
          $$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$



          It can be solve using the "$p$-$q$-formula":
          $$
          cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
          = fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
          $$



          A couple of notes:



          1. The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.

          2. When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.





          share|cite|improve this answer





















          • Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
            – Newbie
            Aug 2 at 16:00










          • Oh, you are right.
            – md2perpe
            Aug 2 at 16:03












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          First we replace $sin a$ with $sqrt1-cos^2a$:
          $$x' = x cos a - y sqrt1-cos^2 a$$



          Then we eliminate the square root by isolating it and squaring:
          $$y sqrt1-cos^2 a = x cos a - x'$$
          $$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$



          This can now be rewritten as a quadric in $cos a$:
          $$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
          $$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$



          It can be solve using the "$p$-$q$-formula":
          $$
          cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
          = fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
          $$



          A couple of notes:



          1. The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.

          2. When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.





          share|cite|improve this answer













          First we replace $sin a$ with $sqrt1-cos^2a$:
          $$x' = x cos a - y sqrt1-cos^2 a$$



          Then we eliminate the square root by isolating it and squaring:
          $$y sqrt1-cos^2 a = x cos a - x'$$
          $$y^2 (1-cos^2 a) = (x cos a - x')^2 = x^2 cos^2 a - 2 x x' cos a + (x')^2$$



          This can now be rewritten as a quadric in $cos a$:
          $$0 = (x^2+y^2) cos^2 a - 2xx' cos a + ((x')^2-y^2)$$
          $$cos^2 a - 2fracxx'x^2+y^2 cos a + frac(x')^2-y^2x^2+y^2 = 0$$



          It can be solve using the "$p$-$q$-formula":
          $$
          cos a = fracxx'x^2+y^2 pm sqrtleft(fracxx'x^2+y^2right)^2 - frac(x')^2-y^2x^2+y^2 \
          = fracxx' pm sqrt(x^2+y^2)y^2-(x')^2y^2x^2+y^2
          $$



          A couple of notes:



          1. The identity $sin a = sqrt1-cos^2a$ is not always valid. For some $a$ we instead have $sin a = -sqrt1-cos^2a.$ You could do this case yourself.

          2. When we square the equation we might add fake solutions. Therefore the solutions should be tested before accepted.






          share|cite|improve this answer













          share|cite|improve this answer



          share|cite|improve this answer











          answered Aug 2 at 13:46









          md2perpe

          5,6191921




          5,6191921











          • Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
            – Newbie
            Aug 2 at 16:00










          • Oh, you are right.
            – md2perpe
            Aug 2 at 16:03
















          • Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
            – Newbie
            Aug 2 at 16:00










          • Oh, you are right.
            – md2perpe
            Aug 2 at 16:03















          Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
          – Newbie
          Aug 2 at 16:00




          Is the case you discussed in your first note actually required? Because you are taking the square of $ ysqrt1-cos^2a $
          – Newbie
          Aug 2 at 16:00












          Oh, you are right.
          – md2perpe
          Aug 2 at 16:03




          Oh, you are right.
          – md2perpe
          Aug 2 at 16:03










          up vote
          2
          down vote













          Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if you’re coding this, there’s likely a two-argument form of the arctangent function available (often called something like ATAN2) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.






          share|cite|improve this answer























          • This is the approach I would have taken. Plus one.
            – Lubin
            Aug 2 at 22:36










          • Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
            – Newbie
            Aug 3 at 1:22















          up vote
          2
          down vote













          Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if you’re coding this, there’s likely a two-argument form of the arctangent function available (often called something like ATAN2) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.






          share|cite|improve this answer























          • This is the approach I would have taken. Plus one.
            – Lubin
            Aug 2 at 22:36










          • Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
            – Newbie
            Aug 3 at 1:22













          up vote
          2
          down vote










          up vote
          2
          down vote









          Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if you’re coding this, there’s likely a two-argument form of the arctangent function available (often called something like ATAN2) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.






          share|cite|improve this answer















          Changing notation a bit, all of the possible rotations of $mathbf p_0=(x_0,y_0)$ lie on a circle with radius $r = |mathbf p_0| = sqrtx_0^2+y_0^2$. An equation of this circle is $x^2+y^2=x_0^2+y_0^2$. Your problem comes down to finding the points on this circle with $x$-coordinate equal to $x_1$. Plugging $x_1$ into the above equation gives you a quadratic equation with solutions $y_1 = pmsqrtr^2-x_1^2$. (You can also get this directly from the Pythagorean theorem.) For each of the solutions $mathbf p_1=(x_1,y_1)$ you can recover the cosine of the angle $alpha$ via the dot product identity: $$mathbf p_0cdotmathbf p_1 = |mathbf p_0|,|mathbf p_1|cosalpha = r^2cosalpha$$ therefore $$cosalpha = x_0x_1+y_0y_1 over x_0^2+y_0^2.tag1$$ Because $cosalpha = cos(-alpha)$, this equation has a sign ambiguity, but you can resolve it by examining $$detbeginbmatrixmathbf p_0^T&mathbf p_1^Tendbmatrix = x_0y_1-x_1y_0 = |mathbf p_0|,|mathbf p_1|sinalpha.tag2$$ You can, if you like, combine these two equations to obtain $$tanalpha = x_0y_1-x_1y_0 over x_0x_1+y_0y_1.$$ This also has an ambiguity, this time of the quadrant of the angle, but if you’re coding this, there’s likely a two-argument form of the arctangent function available (often called something like ATAN2) that allows you to pass the numerator and denominator in separately in order to resolve this ambiguity.







          share|cite|improve this answer















          share|cite|improve this answer



          share|cite|improve this answer








          edited Aug 3 at 1:23


























          answered Aug 2 at 21:23









          amd

          25.7k2943




          25.7k2943











          • This is the approach I would have taken. Plus one.
            – Lubin
            Aug 2 at 22:36










          • Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
            – Newbie
            Aug 3 at 1:22

















          • This is the approach I would have taken. Plus one.
            – Lubin
            Aug 2 at 22:36










          • Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
            – Newbie
            Aug 3 at 1:22
















          This is the approach I would have taken. Plus one.
          – Lubin
          Aug 2 at 22:36




          This is the approach I would have taken. Plus one.
          – Lubin
          Aug 2 at 22:36












          Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
          – Newbie
          Aug 3 at 1:22





          Thanks but I have already accepted the other one. This one looks more generic and simpler as well.
          – Newbie
          Aug 3 at 1:22













           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2870039%2fhow-to-find-angle-of-rotation-given-the-source-point-and-x-coordinate-of-destina%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?

          Relationship between determinant of matrix and determinant of adjoint?

          Color the edges and diagonals of a regular polygon