Apply a rotation matrix to xy coordinates











up vote
0
down vote

favorite












I have xy coordinates that represents a subject over a given space. It is referenced from another point and is therefore off centre. As in the longitudinal axes is not aligned along the x-axis.



The randomly generated ellipse below provides an indication of this:



import numpy as np
from matplotlib.pyplot import scatter

xx = np.array([-0.51, 51.2])
yy = np.array([0.33, 51.6])
means = [xx.mean(), yy.mean()]
stds = [xx.std() / 3, yy.std() / 3]
corr = 0.8 # correlation
covs = [[stds[0]**2 , stds[0]*stds[1]*corr],
[stds[0]*stds[1]*corr, stds[1]**2]]

m = np.random.multivariate_normal(means, covs, 1000).T
scatter(m[0], m[1])


To straighten the coordinates I was thinking of applying the vector to a rotation matrix.



Would something like this work?



angle = 65.
theta = (angle/180.) * np.pi

rotMatrix = np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])


This may also seem like a silly question but is there a way to determine if the resulting vector of xy coordinates is perpendicular? Or will you just have to play around with the rotation angle?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I have xy coordinates that represents a subject over a given space. It is referenced from another point and is therefore off centre. As in the longitudinal axes is not aligned along the x-axis.



    The randomly generated ellipse below provides an indication of this:



    import numpy as np
    from matplotlib.pyplot import scatter

    xx = np.array([-0.51, 51.2])
    yy = np.array([0.33, 51.6])
    means = [xx.mean(), yy.mean()]
    stds = [xx.std() / 3, yy.std() / 3]
    corr = 0.8 # correlation
    covs = [[stds[0]**2 , stds[0]*stds[1]*corr],
    [stds[0]*stds[1]*corr, stds[1]**2]]

    m = np.random.multivariate_normal(means, covs, 1000).T
    scatter(m[0], m[1])


    To straighten the coordinates I was thinking of applying the vector to a rotation matrix.



    Would something like this work?



    angle = 65.
    theta = (angle/180.) * np.pi

    rotMatrix = np.array([[np.cos(theta), -np.sin(theta)],
    [np.sin(theta), np.cos(theta)]])


    This may also seem like a silly question but is there a way to determine if the resulting vector of xy coordinates is perpendicular? Or will you just have to play around with the rotation angle?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have xy coordinates that represents a subject over a given space. It is referenced from another point and is therefore off centre. As in the longitudinal axes is not aligned along the x-axis.



      The randomly generated ellipse below provides an indication of this:



      import numpy as np
      from matplotlib.pyplot import scatter

      xx = np.array([-0.51, 51.2])
      yy = np.array([0.33, 51.6])
      means = [xx.mean(), yy.mean()]
      stds = [xx.std() / 3, yy.std() / 3]
      corr = 0.8 # correlation
      covs = [[stds[0]**2 , stds[0]*stds[1]*corr],
      [stds[0]*stds[1]*corr, stds[1]**2]]

      m = np.random.multivariate_normal(means, covs, 1000).T
      scatter(m[0], m[1])


      To straighten the coordinates I was thinking of applying the vector to a rotation matrix.



      Would something like this work?



      angle = 65.
      theta = (angle/180.) * np.pi

      rotMatrix = np.array([[np.cos(theta), -np.sin(theta)],
      [np.sin(theta), np.cos(theta)]])


      This may also seem like a silly question but is there a way to determine if the resulting vector of xy coordinates is perpendicular? Or will you just have to play around with the rotation angle?










      share|improve this question















      I have xy coordinates that represents a subject over a given space. It is referenced from another point and is therefore off centre. As in the longitudinal axes is not aligned along the x-axis.



      The randomly generated ellipse below provides an indication of this:



      import numpy as np
      from matplotlib.pyplot import scatter

      xx = np.array([-0.51, 51.2])
      yy = np.array([0.33, 51.6])
      means = [xx.mean(), yy.mean()]
      stds = [xx.std() / 3, yy.std() / 3]
      corr = 0.8 # correlation
      covs = [[stds[0]**2 , stds[0]*stds[1]*corr],
      [stds[0]*stds[1]*corr, stds[1]**2]]

      m = np.random.multivariate_normal(means, covs, 1000).T
      scatter(m[0], m[1])


      To straighten the coordinates I was thinking of applying the vector to a rotation matrix.



      Would something like this work?



      angle = 65.
      theta = (angle/180.) * np.pi

      rotMatrix = np.array([[np.cos(theta), -np.sin(theta)],
      [np.sin(theta), np.cos(theta)]])


      This may also seem like a silly question but is there a way to determine if the resulting vector of xy coordinates is perpendicular? Or will you just have to play around with the rotation angle?







      python pandas matplotlib matrix rotation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      Maxibon

      11411




      11411
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          If the slope of the two lines multiplied together is equal to -1 than they are perpendicular.
          The other case this is true, is when one slope is 0 and the other is undefined (a perfectly horizontal line and a perfectly vertical line).






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372015%2fapply-a-rotation-matrix-to-xy-coordinates%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








            up vote
            0
            down vote













            If the slope of the two lines multiplied together is equal to -1 than they are perpendicular.
            The other case this is true, is when one slope is 0 and the other is undefined (a perfectly horizontal line and a perfectly vertical line).






            share|improve this answer

























              up vote
              0
              down vote













              If the slope of the two lines multiplied together is equal to -1 than they are perpendicular.
              The other case this is true, is when one slope is 0 and the other is undefined (a perfectly horizontal line and a perfectly vertical line).






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                If the slope of the two lines multiplied together is equal to -1 than they are perpendicular.
                The other case this is true, is when one slope is 0 and the other is undefined (a perfectly horizontal line and a perfectly vertical line).






                share|improve this answer












                If the slope of the two lines multiplied together is equal to -1 than they are perpendicular.
                The other case this is true, is when one slope is 0 and the other is undefined (a perfectly horizontal line and a perfectly vertical line).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 23 hours ago









                DMarczak

                1119




                1119






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372015%2fapply-a-rotation-matrix-to-xy-coordinates%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

                    Saint-Aignan (Tarn-et-Garonne)

                    Volksrepublik China

                    How to test boost logger output in unit testing?