Universal formula to calculate rotating by angle












0












$begingroup$


I am generating roads and buildings that belong to them and since I want the streets to be rotated and then connected with each other, I need to rotate both them and their respective buildings. Is there a formula that would be able to translate (for example) my (x,y) point into point A given the (x,y) as the topleft corner of a building, (x1,y1) as the start of the street and alpha being the angle I am rotating by?



enter image description here










share|cite|improve this question









$endgroup$

















    0












    $begingroup$


    I am generating roads and buildings that belong to them and since I want the streets to be rotated and then connected with each other, I need to rotate both them and their respective buildings. Is there a formula that would be able to translate (for example) my (x,y) point into point A given the (x,y) as the topleft corner of a building, (x1,y1) as the start of the street and alpha being the angle I am rotating by?



    enter image description here










    share|cite|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I am generating roads and buildings that belong to them and since I want the streets to be rotated and then connected with each other, I need to rotate both them and their respective buildings. Is there a formula that would be able to translate (for example) my (x,y) point into point A given the (x,y) as the topleft corner of a building, (x1,y1) as the start of the street and alpha being the angle I am rotating by?



      enter image description here










      share|cite|improve this question









      $endgroup$




      I am generating roads and buildings that belong to them and since I want the streets to be rotated and then connected with each other, I need to rotate both them and their respective buildings. Is there a formula that would be able to translate (for example) my (x,y) point into point A given the (x,y) as the topleft corner of a building, (x1,y1) as the start of the street and alpha being the angle I am rotating by?



      enter image description here







      trigonometry transformation rotations






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Dec 17 '18 at 20:04









      Andrius NaruševičiusAndrius Naruševičius

      15315




      15315






















          1 Answer
          1






          active

          oldest

          votes


















          1












          $begingroup$

          Yes, there is:



          First, typically in trig we assume $y$ increases when you go up on paper, but you have that flipped. But that's ok, since the angle is typically measured counter-clockwise, while your $alpha$ is measured clock-wise, so the math will actually work out just the same.



          That is, in general, if you have a point that is at $(x,y)$, when assuming the rotation point is the origin $(0,0)$, then if you rotate by $alpha$ degrees, then the new point will be at $(x',y')$, where:



          $$x'=xcdot cos alpha - y cdot sin alpha$$



          $$y'=ycdot cos alpha + x cdot sin alpha$$



          Now, applied to your case, since your point of rotation is not $(0,0)$, but is $(x1,y1)$, we first need to find the points relative to the rotation point $(x1,y1)$, so we need to shift the coordinate system by subtracting$1$ and $y1$. For example your original point $(x,y)$ would be considered at $(x,y)_S=(x-x1,y-y1)$, assuming $(x1,y1)$ is at $(0,0)$.



          $$x_A=(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          OK, but again this is relative to taking $(x1,y1)$ as the origin, so to get the $x$ and $y$ back relative to your coordinate system, we need to add $x1$ and $y1$ back, i.e. we get:



          $$x_A=x1+(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=y1+(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          As another example, point $D$ ends up at:



          $$x_D=x1+(x-x1)cdot cos alpha - (y+h-y1) cdot sin alpha$$



          $$y_D=y1+(y+h-y1)cdot cos alpha + (x-x1) cdot sin alpha$$






          share|cite|improve this answer











          $endgroup$













          • $begingroup$
            This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
            $endgroup$
            – Andrius Naruševičius
            Dec 17 '18 at 20:45










          • $begingroup$
            @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
            $endgroup$
            – Bram28
            Dec 17 '18 at 20:50











          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%2f3044377%2funiversal-formula-to-calculate-rotating-by-angle%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1












          $begingroup$

          Yes, there is:



          First, typically in trig we assume $y$ increases when you go up on paper, but you have that flipped. But that's ok, since the angle is typically measured counter-clockwise, while your $alpha$ is measured clock-wise, so the math will actually work out just the same.



          That is, in general, if you have a point that is at $(x,y)$, when assuming the rotation point is the origin $(0,0)$, then if you rotate by $alpha$ degrees, then the new point will be at $(x',y')$, where:



          $$x'=xcdot cos alpha - y cdot sin alpha$$



          $$y'=ycdot cos alpha + x cdot sin alpha$$



          Now, applied to your case, since your point of rotation is not $(0,0)$, but is $(x1,y1)$, we first need to find the points relative to the rotation point $(x1,y1)$, so we need to shift the coordinate system by subtracting$1$ and $y1$. For example your original point $(x,y)$ would be considered at $(x,y)_S=(x-x1,y-y1)$, assuming $(x1,y1)$ is at $(0,0)$.



          $$x_A=(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          OK, but again this is relative to taking $(x1,y1)$ as the origin, so to get the $x$ and $y$ back relative to your coordinate system, we need to add $x1$ and $y1$ back, i.e. we get:



          $$x_A=x1+(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=y1+(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          As another example, point $D$ ends up at:



          $$x_D=x1+(x-x1)cdot cos alpha - (y+h-y1) cdot sin alpha$$



          $$y_D=y1+(y+h-y1)cdot cos alpha + (x-x1) cdot sin alpha$$






          share|cite|improve this answer











          $endgroup$













          • $begingroup$
            This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
            $endgroup$
            – Andrius Naruševičius
            Dec 17 '18 at 20:45










          • $begingroup$
            @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
            $endgroup$
            – Bram28
            Dec 17 '18 at 20:50
















          1












          $begingroup$

          Yes, there is:



          First, typically in trig we assume $y$ increases when you go up on paper, but you have that flipped. But that's ok, since the angle is typically measured counter-clockwise, while your $alpha$ is measured clock-wise, so the math will actually work out just the same.



          That is, in general, if you have a point that is at $(x,y)$, when assuming the rotation point is the origin $(0,0)$, then if you rotate by $alpha$ degrees, then the new point will be at $(x',y')$, where:



          $$x'=xcdot cos alpha - y cdot sin alpha$$



          $$y'=ycdot cos alpha + x cdot sin alpha$$



          Now, applied to your case, since your point of rotation is not $(0,0)$, but is $(x1,y1)$, we first need to find the points relative to the rotation point $(x1,y1)$, so we need to shift the coordinate system by subtracting$1$ and $y1$. For example your original point $(x,y)$ would be considered at $(x,y)_S=(x-x1,y-y1)$, assuming $(x1,y1)$ is at $(0,0)$.



          $$x_A=(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          OK, but again this is relative to taking $(x1,y1)$ as the origin, so to get the $x$ and $y$ back relative to your coordinate system, we need to add $x1$ and $y1$ back, i.e. we get:



          $$x_A=x1+(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=y1+(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          As another example, point $D$ ends up at:



          $$x_D=x1+(x-x1)cdot cos alpha - (y+h-y1) cdot sin alpha$$



          $$y_D=y1+(y+h-y1)cdot cos alpha + (x-x1) cdot sin alpha$$






          share|cite|improve this answer











          $endgroup$













          • $begingroup$
            This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
            $endgroup$
            – Andrius Naruševičius
            Dec 17 '18 at 20:45










          • $begingroup$
            @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
            $endgroup$
            – Bram28
            Dec 17 '18 at 20:50














          1












          1








          1





          $begingroup$

          Yes, there is:



          First, typically in trig we assume $y$ increases when you go up on paper, but you have that flipped. But that's ok, since the angle is typically measured counter-clockwise, while your $alpha$ is measured clock-wise, so the math will actually work out just the same.



          That is, in general, if you have a point that is at $(x,y)$, when assuming the rotation point is the origin $(0,0)$, then if you rotate by $alpha$ degrees, then the new point will be at $(x',y')$, where:



          $$x'=xcdot cos alpha - y cdot sin alpha$$



          $$y'=ycdot cos alpha + x cdot sin alpha$$



          Now, applied to your case, since your point of rotation is not $(0,0)$, but is $(x1,y1)$, we first need to find the points relative to the rotation point $(x1,y1)$, so we need to shift the coordinate system by subtracting$1$ and $y1$. For example your original point $(x,y)$ would be considered at $(x,y)_S=(x-x1,y-y1)$, assuming $(x1,y1)$ is at $(0,0)$.



          $$x_A=(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          OK, but again this is relative to taking $(x1,y1)$ as the origin, so to get the $x$ and $y$ back relative to your coordinate system, we need to add $x1$ and $y1$ back, i.e. we get:



          $$x_A=x1+(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=y1+(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          As another example, point $D$ ends up at:



          $$x_D=x1+(x-x1)cdot cos alpha - (y+h-y1) cdot sin alpha$$



          $$y_D=y1+(y+h-y1)cdot cos alpha + (x-x1) cdot sin alpha$$






          share|cite|improve this answer











          $endgroup$



          Yes, there is:



          First, typically in trig we assume $y$ increases when you go up on paper, but you have that flipped. But that's ok, since the angle is typically measured counter-clockwise, while your $alpha$ is measured clock-wise, so the math will actually work out just the same.



          That is, in general, if you have a point that is at $(x,y)$, when assuming the rotation point is the origin $(0,0)$, then if you rotate by $alpha$ degrees, then the new point will be at $(x',y')$, where:



          $$x'=xcdot cos alpha - y cdot sin alpha$$



          $$y'=ycdot cos alpha + x cdot sin alpha$$



          Now, applied to your case, since your point of rotation is not $(0,0)$, but is $(x1,y1)$, we first need to find the points relative to the rotation point $(x1,y1)$, so we need to shift the coordinate system by subtracting$1$ and $y1$. For example your original point $(x,y)$ would be considered at $(x,y)_S=(x-x1,y-y1)$, assuming $(x1,y1)$ is at $(0,0)$.



          $$x_A=(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          OK, but again this is relative to taking $(x1,y1)$ as the origin, so to get the $x$ and $y$ back relative to your coordinate system, we need to add $x1$ and $y1$ back, i.e. we get:



          $$x_A=x1+(x-x1)cdot cos alpha - (y-y1) cdot sin alpha$$



          $$y_A=y1+(y-y1)cdot cos alpha + (x-x1) cdot sin alpha$$



          As another example, point $D$ ends up at:



          $$x_D=x1+(x-x1)cdot cos alpha - (y+h-y1) cdot sin alpha$$



          $$y_D=y1+(y+h-y1)cdot cos alpha + (x-x1) cdot sin alpha$$







          share|cite|improve this answer














          share|cite|improve this answer



          share|cite|improve this answer








          edited Dec 17 '18 at 20:32

























          answered Dec 17 '18 at 20:20









          Bram28Bram28

          63.1k44793




          63.1k44793












          • $begingroup$
            This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
            $endgroup$
            – Andrius Naruševičius
            Dec 17 '18 at 20:45










          • $begingroup$
            @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
            $endgroup$
            – Bram28
            Dec 17 '18 at 20:50


















          • $begingroup$
            This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
            $endgroup$
            – Andrius Naruševičius
            Dec 17 '18 at 20:45










          • $begingroup$
            @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
            $endgroup$
            – Bram28
            Dec 17 '18 at 20:50
















          $begingroup$
          This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
          $endgroup$
          – Andrius Naruševičius
          Dec 17 '18 at 20:45




          $begingroup$
          This is amazing, I actually managed to make it work from first try: imgur.com/a/HQZonnK Thank you so much!!!
          $endgroup$
          – Andrius Naruševičius
          Dec 17 '18 at 20:45












          $begingroup$
          @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
          $endgroup$
          – Bram28
          Dec 17 '18 at 20:50




          $begingroup$
          @AndriusNaruševičius Ha! I was afraid (and in fact fully expected) that I forgot a negation somewhere, for that's so easy to do ... so it's surprising to me too it works on the first try! :) Thanks for your feedback and glad I could help!
          $endgroup$
          – Bram28
          Dec 17 '18 at 20:50


















          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%2f3044377%2funiversal-formula-to-calculate-rotating-by-angle%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

          Wiesbaden

          Marschland

          Dieringhausen