Use a matrix to rotate a vector in the direction of another vector

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











up vote
0
down vote

favorite












I have two 3D vectors, say A and B, that are perpendicular to each other in an arbitrary plane in 3D space. A and B share origin point P. I would like to rotate vector A in this plane (pivoting about point P) towards vector B by a certain number of degrees $theta$ (or away from B if $theta$ is negative). I would like to do this via a transformation matrix, but I'm having some trouble crafting one on my own. How would I go about this?







share|cite|improve this question





















  • In your idea vectors A and B have an origin in common?
    – gimusi
    Jul 25 at 22:07










  • and is the plane through the origin?
    – gimusi
    Jul 25 at 22:12










  • @gimusi yes and yes
    – derekantrican
    Jul 26 at 12:55










  • ok then I can revise my answer a little bit to simplify that, if you have some numerica example I can try to solve it
    – gimusi
    Jul 26 at 12:57










  • @gimusi I have updated my question a little bit. I will try to draw a picture or something
    – derekantrican
    Jul 26 at 13:00














up vote
0
down vote

favorite












I have two 3D vectors, say A and B, that are perpendicular to each other in an arbitrary plane in 3D space. A and B share origin point P. I would like to rotate vector A in this plane (pivoting about point P) towards vector B by a certain number of degrees $theta$ (or away from B if $theta$ is negative). I would like to do this via a transformation matrix, but I'm having some trouble crafting one on my own. How would I go about this?







share|cite|improve this question





















  • In your idea vectors A and B have an origin in common?
    – gimusi
    Jul 25 at 22:07










  • and is the plane through the origin?
    – gimusi
    Jul 25 at 22:12










  • @gimusi yes and yes
    – derekantrican
    Jul 26 at 12:55










  • ok then I can revise my answer a little bit to simplify that, if you have some numerica example I can try to solve it
    – gimusi
    Jul 26 at 12:57










  • @gimusi I have updated my question a little bit. I will try to draw a picture or something
    – derekantrican
    Jul 26 at 13:00












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have two 3D vectors, say A and B, that are perpendicular to each other in an arbitrary plane in 3D space. A and B share origin point P. I would like to rotate vector A in this plane (pivoting about point P) towards vector B by a certain number of degrees $theta$ (or away from B if $theta$ is negative). I would like to do this via a transformation matrix, but I'm having some trouble crafting one on my own. How would I go about this?







share|cite|improve this question













I have two 3D vectors, say A and B, that are perpendicular to each other in an arbitrary plane in 3D space. A and B share origin point P. I would like to rotate vector A in this plane (pivoting about point P) towards vector B by a certain number of degrees $theta$ (or away from B if $theta$ is negative). I would like to do this via a transformation matrix, but I'm having some trouble crafting one on my own. How would I go about this?









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited Jul 26 at 12:59
























asked Jul 25 at 21:55









derekantrican

1104




1104











  • In your idea vectors A and B have an origin in common?
    – gimusi
    Jul 25 at 22:07










  • and is the plane through the origin?
    – gimusi
    Jul 25 at 22:12










  • @gimusi yes and yes
    – derekantrican
    Jul 26 at 12:55










  • ok then I can revise my answer a little bit to simplify that, if you have some numerica example I can try to solve it
    – gimusi
    Jul 26 at 12:57










  • @gimusi I have updated my question a little bit. I will try to draw a picture or something
    – derekantrican
    Jul 26 at 13:00
















  • In your idea vectors A and B have an origin in common?
    – gimusi
    Jul 25 at 22:07










  • and is the plane through the origin?
    – gimusi
    Jul 25 at 22:12










  • @gimusi yes and yes
    – derekantrican
    Jul 26 at 12:55










  • ok then I can revise my answer a little bit to simplify that, if you have some numerica example I can try to solve it
    – gimusi
    Jul 26 at 12:57










  • @gimusi I have updated my question a little bit. I will try to draw a picture or something
    – derekantrican
    Jul 26 at 13:00















In your idea vectors A and B have an origin in common?
– gimusi
Jul 25 at 22:07




In your idea vectors A and B have an origin in common?
– gimusi
Jul 25 at 22:07












and is the plane through the origin?
– gimusi
Jul 25 at 22:12




and is the plane through the origin?
– gimusi
Jul 25 at 22:12












@gimusi yes and yes
– derekantrican
Jul 26 at 12:55




@gimusi yes and yes
– derekantrican
Jul 26 at 12:55












ok then I can revise my answer a little bit to simplify that, if you have some numerica example I can try to solve it
– gimusi
Jul 26 at 12:57




ok then I can revise my answer a little bit to simplify that, if you have some numerica example I can try to solve it
– gimusi
Jul 26 at 12:57












@gimusi I have updated my question a little bit. I will try to draw a picture or something
– derekantrican
Jul 26 at 13:00




@gimusi I have updated my question a little bit. I will try to draw a picture or something
– derekantrican
Jul 26 at 13:00










4 Answers
4






active

oldest

votes

















up vote
3
down vote



accepted










You don’t really need to construct a matrix to do this. Since $A$ and $B$ are orthogonal, $mathbf u = A/|A|$ and $mathbf v = B/|B|$ form an orthonormal basis for their common plane. If you rotate $mathbf u$ through an angle $theta$ toward $mathbf v$, you get $mathbf ucostheta+mathbf vsintheta$, so to rotate $A$ toward $B$, simply multiply this by $|A|$, i.e., $$Acostheta + B Bsintheta.$$



If you really want a matrix, you can use Rodrigues’ rotation formula to construct one. Let $mathbf n = $, the right-handed normal to the plane of rotation, and designate by $mathbf N$ its “cross-product matrix” $$mathbf N = beginbmatrix0&-n_z&n_y\n_z&0&-n_x\-n_y&n_x&0endbmatrix.$$ The corresponding rotation matrix is then $$mathbf R = mathbf I + (sintheta)mathbf N + (1-costheta)mathbf N^2.$$






share|cite|improve this answer























  • We don't need but we can always do that! By the way, very useful answer.
    – gimusi
    Jul 26 at 13:04










  • Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
    – derekantrican
    Jul 26 at 15:52


















up vote
0
down vote













Hint:



first, move your reference system to be in $x'=A/|A|,y'=B/|B|,z'=(A/|A|) times (B/|B|)$, through the corresponding transformation matrix T;



then apply a rotation matrix $R$ bringing $x'$ towards $y'$ by the required angle



finally multiply by $T^-1$






share|cite|improve this answer




























    up vote
    0
    down vote













    First replace $A$ by $A/|A|$, and similarly for $B$, so that they're unit vectors.



    Compute $C = A times B$, the cross product. Let $M$ by the matrix whose columns are $A, B, C$; then $M^-1$ happens to be $M^t$, which is easy to compute -- just put in $A, B, C$ as the rows!



    Now let
    $$
    R = M S M^-1 = M S M^t
    $$
    where
    $$
    S = pmatrixc & -s & 0 \
    s & c & 0 \
    0 & 0 & 1
    $$
    where $c = cos theta$ and $s = sin theta$, and $R$ is the rotation matrix that you want.



    NB: Note that if $theta$ is in degrees, then you need to use $c = cos (pi * theta / 180)$, and similarly for $s$, where $sin$ and $cos$ denote the usual functions that work on angles expressed in radians.






    share|cite|improve this answer




























      up vote
      0
      down vote













      We can proceed as follow



      1. Fix a basis $mathcalB=v_1,v_2,v_3$ with $v_1=n$ is the normal to the plane, $v_2=A$ and $v_3=B$.

      2. Then write the rotation matrix $R_mathcalB$ with respect to that basis (we can use the standard rotation matrix).

      3. Then with respect to the canonical basis, indicating with $M=[v_1,v_2,v_3]$ we have

      $$w_mathcalB=R_mathcalBv_mathcalB implies M^-1w=R_mathcalBM^-1vimplies w=MR_mathcalBM^-1v=Rv$$






      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%2f2862858%2fuse-a-matrix-to-rotate-a-vector-in-the-direction-of-another-vector%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        3
        down vote



        accepted










        You don’t really need to construct a matrix to do this. Since $A$ and $B$ are orthogonal, $mathbf u = A/|A|$ and $mathbf v = B/|B|$ form an orthonormal basis for their common plane. If you rotate $mathbf u$ through an angle $theta$ toward $mathbf v$, you get $mathbf ucostheta+mathbf vsintheta$, so to rotate $A$ toward $B$, simply multiply this by $|A|$, i.e., $$Acostheta + B Bsintheta.$$



        If you really want a matrix, you can use Rodrigues’ rotation formula to construct one. Let $mathbf n = $, the right-handed normal to the plane of rotation, and designate by $mathbf N$ its “cross-product matrix” $$mathbf N = beginbmatrix0&-n_z&n_y\n_z&0&-n_x\-n_y&n_x&0endbmatrix.$$ The corresponding rotation matrix is then $$mathbf R = mathbf I + (sintheta)mathbf N + (1-costheta)mathbf N^2.$$






        share|cite|improve this answer























        • We don't need but we can always do that! By the way, very useful answer.
          – gimusi
          Jul 26 at 13:04










        • Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
          – derekantrican
          Jul 26 at 15:52















        up vote
        3
        down vote



        accepted










        You don’t really need to construct a matrix to do this. Since $A$ and $B$ are orthogonal, $mathbf u = A/|A|$ and $mathbf v = B/|B|$ form an orthonormal basis for their common plane. If you rotate $mathbf u$ through an angle $theta$ toward $mathbf v$, you get $mathbf ucostheta+mathbf vsintheta$, so to rotate $A$ toward $B$, simply multiply this by $|A|$, i.e., $$Acostheta + B Bsintheta.$$



        If you really want a matrix, you can use Rodrigues’ rotation formula to construct one. Let $mathbf n = $, the right-handed normal to the plane of rotation, and designate by $mathbf N$ its “cross-product matrix” $$mathbf N = beginbmatrix0&-n_z&n_y\n_z&0&-n_x\-n_y&n_x&0endbmatrix.$$ The corresponding rotation matrix is then $$mathbf R = mathbf I + (sintheta)mathbf N + (1-costheta)mathbf N^2.$$






        share|cite|improve this answer























        • We don't need but we can always do that! By the way, very useful answer.
          – gimusi
          Jul 26 at 13:04










        • Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
          – derekantrican
          Jul 26 at 15:52













        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        You don’t really need to construct a matrix to do this. Since $A$ and $B$ are orthogonal, $mathbf u = A/|A|$ and $mathbf v = B/|B|$ form an orthonormal basis for their common plane. If you rotate $mathbf u$ through an angle $theta$ toward $mathbf v$, you get $mathbf ucostheta+mathbf vsintheta$, so to rotate $A$ toward $B$, simply multiply this by $|A|$, i.e., $$Acostheta + B Bsintheta.$$



        If you really want a matrix, you can use Rodrigues’ rotation formula to construct one. Let $mathbf n = $, the right-handed normal to the plane of rotation, and designate by $mathbf N$ its “cross-product matrix” $$mathbf N = beginbmatrix0&-n_z&n_y\n_z&0&-n_x\-n_y&n_x&0endbmatrix.$$ The corresponding rotation matrix is then $$mathbf R = mathbf I + (sintheta)mathbf N + (1-costheta)mathbf N^2.$$






        share|cite|improve this answer















        You don’t really need to construct a matrix to do this. Since $A$ and $B$ are orthogonal, $mathbf u = A/|A|$ and $mathbf v = B/|B|$ form an orthonormal basis for their common plane. If you rotate $mathbf u$ through an angle $theta$ toward $mathbf v$, you get $mathbf ucostheta+mathbf vsintheta$, so to rotate $A$ toward $B$, simply multiply this by $|A|$, i.e., $$Acostheta + B Bsintheta.$$



        If you really want a matrix, you can use Rodrigues’ rotation formula to construct one. Let $mathbf n = $, the right-handed normal to the plane of rotation, and designate by $mathbf N$ its “cross-product matrix” $$mathbf N = beginbmatrix0&-n_z&n_y\n_z&0&-n_x\-n_y&n_x&0endbmatrix.$$ The corresponding rotation matrix is then $$mathbf R = mathbf I + (sintheta)mathbf N + (1-costheta)mathbf N^2.$$







        share|cite|improve this answer















        share|cite|improve this answer



        share|cite|improve this answer








        edited Jul 26 at 8:33


























        answered Jul 26 at 8:14









        amd

        25.8k2943




        25.8k2943











        • We don't need but we can always do that! By the way, very useful answer.
          – gimusi
          Jul 26 at 13:04










        • Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
          – derekantrican
          Jul 26 at 15:52

















        • We don't need but we can always do that! By the way, very useful answer.
          – gimusi
          Jul 26 at 13:04










        • Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
          – derekantrican
          Jul 26 at 15:52
















        We don't need but we can always do that! By the way, very useful answer.
        – gimusi
        Jul 26 at 13:04




        We don't need but we can always do that! By the way, very useful answer.
        – gimusi
        Jul 26 at 13:04












        Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
        – derekantrican
        Jul 26 at 15:52





        Excellent. Your first solution Acosθ+(∥A∥/∥B∥)Bsinθ ended up being what I used. Thank you!
        – derekantrican
        Jul 26 at 15:52











        up vote
        0
        down vote













        Hint:



        first, move your reference system to be in $x'=A/|A|,y'=B/|B|,z'=(A/|A|) times (B/|B|)$, through the corresponding transformation matrix T;



        then apply a rotation matrix $R$ bringing $x'$ towards $y'$ by the required angle



        finally multiply by $T^-1$






        share|cite|improve this answer

























          up vote
          0
          down vote













          Hint:



          first, move your reference system to be in $x'=A/|A|,y'=B/|B|,z'=(A/|A|) times (B/|B|)$, through the corresponding transformation matrix T;



          then apply a rotation matrix $R$ bringing $x'$ towards $y'$ by the required angle



          finally multiply by $T^-1$






          share|cite|improve this answer























            up vote
            0
            down vote










            up vote
            0
            down vote









            Hint:



            first, move your reference system to be in $x'=A/|A|,y'=B/|B|,z'=(A/|A|) times (B/|B|)$, through the corresponding transformation matrix T;



            then apply a rotation matrix $R$ bringing $x'$ towards $y'$ by the required angle



            finally multiply by $T^-1$






            share|cite|improve this answer













            Hint:



            first, move your reference system to be in $x'=A/|A|,y'=B/|B|,z'=(A/|A|) times (B/|B|)$, through the corresponding transformation matrix T;



            then apply a rotation matrix $R$ bringing $x'$ towards $y'$ by the required angle



            finally multiply by $T^-1$







            share|cite|improve this answer













            share|cite|improve this answer



            share|cite|improve this answer











            answered Jul 25 at 22:09









            G Cab

            15.1k31136




            15.1k31136




















                up vote
                0
                down vote













                First replace $A$ by $A/|A|$, and similarly for $B$, so that they're unit vectors.



                Compute $C = A times B$, the cross product. Let $M$ by the matrix whose columns are $A, B, C$; then $M^-1$ happens to be $M^t$, which is easy to compute -- just put in $A, B, C$ as the rows!



                Now let
                $$
                R = M S M^-1 = M S M^t
                $$
                where
                $$
                S = pmatrixc & -s & 0 \
                s & c & 0 \
                0 & 0 & 1
                $$
                where $c = cos theta$ and $s = sin theta$, and $R$ is the rotation matrix that you want.



                NB: Note that if $theta$ is in degrees, then you need to use $c = cos (pi * theta / 180)$, and similarly for $s$, where $sin$ and $cos$ denote the usual functions that work on angles expressed in radians.






                share|cite|improve this answer

























                  up vote
                  0
                  down vote













                  First replace $A$ by $A/|A|$, and similarly for $B$, so that they're unit vectors.



                  Compute $C = A times B$, the cross product. Let $M$ by the matrix whose columns are $A, B, C$; then $M^-1$ happens to be $M^t$, which is easy to compute -- just put in $A, B, C$ as the rows!



                  Now let
                  $$
                  R = M S M^-1 = M S M^t
                  $$
                  where
                  $$
                  S = pmatrixc & -s & 0 \
                  s & c & 0 \
                  0 & 0 & 1
                  $$
                  where $c = cos theta$ and $s = sin theta$, and $R$ is the rotation matrix that you want.



                  NB: Note that if $theta$ is in degrees, then you need to use $c = cos (pi * theta / 180)$, and similarly for $s$, where $sin$ and $cos$ denote the usual functions that work on angles expressed in radians.






                  share|cite|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    First replace $A$ by $A/|A|$, and similarly for $B$, so that they're unit vectors.



                    Compute $C = A times B$, the cross product. Let $M$ by the matrix whose columns are $A, B, C$; then $M^-1$ happens to be $M^t$, which is easy to compute -- just put in $A, B, C$ as the rows!



                    Now let
                    $$
                    R = M S M^-1 = M S M^t
                    $$
                    where
                    $$
                    S = pmatrixc & -s & 0 \
                    s & c & 0 \
                    0 & 0 & 1
                    $$
                    where $c = cos theta$ and $s = sin theta$, and $R$ is the rotation matrix that you want.



                    NB: Note that if $theta$ is in degrees, then you need to use $c = cos (pi * theta / 180)$, and similarly for $s$, where $sin$ and $cos$ denote the usual functions that work on angles expressed in radians.






                    share|cite|improve this answer













                    First replace $A$ by $A/|A|$, and similarly for $B$, so that they're unit vectors.



                    Compute $C = A times B$, the cross product. Let $M$ by the matrix whose columns are $A, B, C$; then $M^-1$ happens to be $M^t$, which is easy to compute -- just put in $A, B, C$ as the rows!



                    Now let
                    $$
                    R = M S M^-1 = M S M^t
                    $$
                    where
                    $$
                    S = pmatrixc & -s & 0 \
                    s & c & 0 \
                    0 & 0 & 1
                    $$
                    where $c = cos theta$ and $s = sin theta$, and $R$ is the rotation matrix that you want.



                    NB: Note that if $theta$ is in degrees, then you need to use $c = cos (pi * theta / 180)$, and similarly for $s$, where $sin$ and $cos$ denote the usual functions that work on angles expressed in radians.







                    share|cite|improve this answer













                    share|cite|improve this answer



                    share|cite|improve this answer











                    answered Jul 25 at 22:15









                    John Hughes

                    59.4k23785




                    59.4k23785




















                        up vote
                        0
                        down vote













                        We can proceed as follow



                        1. Fix a basis $mathcalB=v_1,v_2,v_3$ with $v_1=n$ is the normal to the plane, $v_2=A$ and $v_3=B$.

                        2. Then write the rotation matrix $R_mathcalB$ with respect to that basis (we can use the standard rotation matrix).

                        3. Then with respect to the canonical basis, indicating with $M=[v_1,v_2,v_3]$ we have

                        $$w_mathcalB=R_mathcalBv_mathcalB implies M^-1w=R_mathcalBM^-1vimplies w=MR_mathcalBM^-1v=Rv$$






                        share|cite|improve this answer



























                          up vote
                          0
                          down vote













                          We can proceed as follow



                          1. Fix a basis $mathcalB=v_1,v_2,v_3$ with $v_1=n$ is the normal to the plane, $v_2=A$ and $v_3=B$.

                          2. Then write the rotation matrix $R_mathcalB$ with respect to that basis (we can use the standard rotation matrix).

                          3. Then with respect to the canonical basis, indicating with $M=[v_1,v_2,v_3]$ we have

                          $$w_mathcalB=R_mathcalBv_mathcalB implies M^-1w=R_mathcalBM^-1vimplies w=MR_mathcalBM^-1v=Rv$$






                          share|cite|improve this answer

























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            We can proceed as follow



                            1. Fix a basis $mathcalB=v_1,v_2,v_3$ with $v_1=n$ is the normal to the plane, $v_2=A$ and $v_3=B$.

                            2. Then write the rotation matrix $R_mathcalB$ with respect to that basis (we can use the standard rotation matrix).

                            3. Then with respect to the canonical basis, indicating with $M=[v_1,v_2,v_3]$ we have

                            $$w_mathcalB=R_mathcalBv_mathcalB implies M^-1w=R_mathcalBM^-1vimplies w=MR_mathcalBM^-1v=Rv$$






                            share|cite|improve this answer















                            We can proceed as follow



                            1. Fix a basis $mathcalB=v_1,v_2,v_3$ with $v_1=n$ is the normal to the plane, $v_2=A$ and $v_3=B$.

                            2. Then write the rotation matrix $R_mathcalB$ with respect to that basis (we can use the standard rotation matrix).

                            3. Then with respect to the canonical basis, indicating with $M=[v_1,v_2,v_3]$ we have

                            $$w_mathcalB=R_mathcalBv_mathcalB implies M^-1w=R_mathcalBM^-1vimplies w=MR_mathcalBM^-1v=Rv$$







                            share|cite|improve this answer















                            share|cite|improve this answer



                            share|cite|improve this answer








                            edited Jul 26 at 13:03


























                            answered Jul 25 at 22:27









                            gimusi

                            65k73583




                            65k73583






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2862858%2fuse-a-matrix-to-rotate-a-vector-in-the-direction-of-another-vector%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?