How to calculate rotation quaternion between two orientation quaternions?












0












$begingroup$


I have some device (3D pointer) connected to my computer which returns it's position (in cartesian XYZ system) and orientation (in quaternions). I receive this values about 30 times/sec.



Now I need to draw a figure on a screen that has the same position and orientation that my pointer. The position is simple, I can directly pass X,Y and Z to my software.



The problem is that the software doesn't accept orientation (a state) but only rotation (an operation). So I think I should calculate a difference between current and previous orientation - this would be my rotation operation.



Any ideas on how to do this? What quaternion operations should be done to get rotation out of two consecutive orientations?










share|cite|improve this question









$endgroup$

















    0












    $begingroup$


    I have some device (3D pointer) connected to my computer which returns it's position (in cartesian XYZ system) and orientation (in quaternions). I receive this values about 30 times/sec.



    Now I need to draw a figure on a screen that has the same position and orientation that my pointer. The position is simple, I can directly pass X,Y and Z to my software.



    The problem is that the software doesn't accept orientation (a state) but only rotation (an operation). So I think I should calculate a difference between current and previous orientation - this would be my rotation operation.



    Any ideas on how to do this? What quaternion operations should be done to get rotation out of two consecutive orientations?










    share|cite|improve this question









    $endgroup$















      0












      0








      0





      $begingroup$


      I have some device (3D pointer) connected to my computer which returns it's position (in cartesian XYZ system) and orientation (in quaternions). I receive this values about 30 times/sec.



      Now I need to draw a figure on a screen that has the same position and orientation that my pointer. The position is simple, I can directly pass X,Y and Z to my software.



      The problem is that the software doesn't accept orientation (a state) but only rotation (an operation). So I think I should calculate a difference between current and previous orientation - this would be my rotation operation.



      Any ideas on how to do this? What quaternion operations should be done to get rotation out of two consecutive orientations?










      share|cite|improve this question









      $endgroup$




      I have some device (3D pointer) connected to my computer which returns it's position (in cartesian XYZ system) and orientation (in quaternions). I receive this values about 30 times/sec.



      Now I need to draw a figure on a screen that has the same position and orientation that my pointer. The position is simple, I can directly pass X,Y and Z to my software.



      The problem is that the software doesn't accept orientation (a state) but only rotation (an operation). So I think I should calculate a difference between current and previous orientation - this would be my rotation operation.



      Any ideas on how to do this? What quaternion operations should be done to get rotation out of two consecutive orientations?







      3d rotations quaternions orientation






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked May 12 '16 at 11:18









      crooveckcrooveck

      1034




      1034






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          If $$mathbf{q_1} = w_1 + x_1mathbf{i} + y_1mathbf{j} + z_1mathbf{k}$$ is an unit quaternion, $$w_1^2 + x_1^2 + y_1^2 + z_1^2 = 1$$representing the first (earlier) rotation, and $$mathbf{q_2} = w_2 + x_2mathbf{i} + y_2mathbf{j} + z_2mathbf{k}$$ is a second (later) rotation, then their Hamilton product represents the combined rotation,
          $$begin{align}mathbf{q} = mathbf{q_2} mathbf{q_1} = ; & w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2\
          + ; & (w_1 x_2 + w_2 x_1 - y_1 z_2 + y_2 z_1) ; mathbf{i}\
          + ; & (w_1 y_2 + w_2 y_1 + x_1 z_2 - x_2 z_1) ; mathbf{j}\
          + ; & (w_1 z_2 + w_2 z_1 - x_1 y_2 + x_2 y_1) ; mathbf{k}
          end{align}$$
          Note that the Hamilton product is not commutative; the order of the quaternions matters. The result is also an unit quaternion, except for any numerical errors that might creep in. Fortunately, you can always normalize the rotation quaternion,
          $$mathbf{q'} = frac{w + x ;mathbf{i} + y ;mathbf{j} + z ;mathbf{k}}{sqrt{w^2 + x^2 + y^2 + z^2}}$$
          to avoid compounding errors. (It is basically safe to do after each operation, but usually necessary only after a few products.)



          The inverse of a rotation is
          $$mathbf{q}^{-1} = w - x ;mathbf{i} - y ;mathbf{j} - z ;mathbf{k}$$
          ie. negating all components of an unit quaternion, except for the scalar component $w$, inverts the rotation. (Negating all components does not change the rotation it represents.)



          You can also interpolate between two unit quaternions, $0 le p le 1$,
          $$begin{align}mathbf{q'} = (1-p)mathbf{q_1} + pmathbf{q_2} & = w_1 + p (w_2 - w_1)\
          & + left( x_1 + p (x_2 - x_1) right ) ; mathbf{i} \
          & + left( y_1 + p (y_2 - y_1) right ) ; mathbf{j} \
          & + left( z_1 + p (z_2 - z_1) right ) ; mathbf{k}end{align}$$
          if you normalize the result to unit length,
          $$mathbf{q} = frac{w + x' ;mathbf{i} + y' ;mathbf{j} + z' ;mathbf{k}}{sqrt{w'^2 + x'^2 + y'^2 + z'^2}}$$
          This is very useful in camera movement between two orientations. To get a really smooth change, use e.g.
          $$p = 3 p'^2 - 2 p'^3$$
          or
          $$p = 6 p'^5 - 15 p'^4 + 10 p'^3$$
          with $0 le p' le 1$. Both start and stop with zero velocity, but the former has a fixed rate of change of acceleration ("jerk"), and the latter starts and stops with zero acceleration.






          share|cite|improve this answer









          $endgroup$














            Your Answer








            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%2f1782243%2fhow-to-calculate-rotation-quaternion-between-two-orientation-quaternions%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









            0












            $begingroup$

            If $$mathbf{q_1} = w_1 + x_1mathbf{i} + y_1mathbf{j} + z_1mathbf{k}$$ is an unit quaternion, $$w_1^2 + x_1^2 + y_1^2 + z_1^2 = 1$$representing the first (earlier) rotation, and $$mathbf{q_2} = w_2 + x_2mathbf{i} + y_2mathbf{j} + z_2mathbf{k}$$ is a second (later) rotation, then their Hamilton product represents the combined rotation,
            $$begin{align}mathbf{q} = mathbf{q_2} mathbf{q_1} = ; & w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2\
            + ; & (w_1 x_2 + w_2 x_1 - y_1 z_2 + y_2 z_1) ; mathbf{i}\
            + ; & (w_1 y_2 + w_2 y_1 + x_1 z_2 - x_2 z_1) ; mathbf{j}\
            + ; & (w_1 z_2 + w_2 z_1 - x_1 y_2 + x_2 y_1) ; mathbf{k}
            end{align}$$
            Note that the Hamilton product is not commutative; the order of the quaternions matters. The result is also an unit quaternion, except for any numerical errors that might creep in. Fortunately, you can always normalize the rotation quaternion,
            $$mathbf{q'} = frac{w + x ;mathbf{i} + y ;mathbf{j} + z ;mathbf{k}}{sqrt{w^2 + x^2 + y^2 + z^2}}$$
            to avoid compounding errors. (It is basically safe to do after each operation, but usually necessary only after a few products.)



            The inverse of a rotation is
            $$mathbf{q}^{-1} = w - x ;mathbf{i} - y ;mathbf{j} - z ;mathbf{k}$$
            ie. negating all components of an unit quaternion, except for the scalar component $w$, inverts the rotation. (Negating all components does not change the rotation it represents.)



            You can also interpolate between two unit quaternions, $0 le p le 1$,
            $$begin{align}mathbf{q'} = (1-p)mathbf{q_1} + pmathbf{q_2} & = w_1 + p (w_2 - w_1)\
            & + left( x_1 + p (x_2 - x_1) right ) ; mathbf{i} \
            & + left( y_1 + p (y_2 - y_1) right ) ; mathbf{j} \
            & + left( z_1 + p (z_2 - z_1) right ) ; mathbf{k}end{align}$$
            if you normalize the result to unit length,
            $$mathbf{q} = frac{w + x' ;mathbf{i} + y' ;mathbf{j} + z' ;mathbf{k}}{sqrt{w'^2 + x'^2 + y'^2 + z'^2}}$$
            This is very useful in camera movement between two orientations. To get a really smooth change, use e.g.
            $$p = 3 p'^2 - 2 p'^3$$
            or
            $$p = 6 p'^5 - 15 p'^4 + 10 p'^3$$
            with $0 le p' le 1$. Both start and stop with zero velocity, but the former has a fixed rate of change of acceleration ("jerk"), and the latter starts and stops with zero acceleration.






            share|cite|improve this answer









            $endgroup$


















              0












              $begingroup$

              If $$mathbf{q_1} = w_1 + x_1mathbf{i} + y_1mathbf{j} + z_1mathbf{k}$$ is an unit quaternion, $$w_1^2 + x_1^2 + y_1^2 + z_1^2 = 1$$representing the first (earlier) rotation, and $$mathbf{q_2} = w_2 + x_2mathbf{i} + y_2mathbf{j} + z_2mathbf{k}$$ is a second (later) rotation, then their Hamilton product represents the combined rotation,
              $$begin{align}mathbf{q} = mathbf{q_2} mathbf{q_1} = ; & w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2\
              + ; & (w_1 x_2 + w_2 x_1 - y_1 z_2 + y_2 z_1) ; mathbf{i}\
              + ; & (w_1 y_2 + w_2 y_1 + x_1 z_2 - x_2 z_1) ; mathbf{j}\
              + ; & (w_1 z_2 + w_2 z_1 - x_1 y_2 + x_2 y_1) ; mathbf{k}
              end{align}$$
              Note that the Hamilton product is not commutative; the order of the quaternions matters. The result is also an unit quaternion, except for any numerical errors that might creep in. Fortunately, you can always normalize the rotation quaternion,
              $$mathbf{q'} = frac{w + x ;mathbf{i} + y ;mathbf{j} + z ;mathbf{k}}{sqrt{w^2 + x^2 + y^2 + z^2}}$$
              to avoid compounding errors. (It is basically safe to do after each operation, but usually necessary only after a few products.)



              The inverse of a rotation is
              $$mathbf{q}^{-1} = w - x ;mathbf{i} - y ;mathbf{j} - z ;mathbf{k}$$
              ie. negating all components of an unit quaternion, except for the scalar component $w$, inverts the rotation. (Negating all components does not change the rotation it represents.)



              You can also interpolate between two unit quaternions, $0 le p le 1$,
              $$begin{align}mathbf{q'} = (1-p)mathbf{q_1} + pmathbf{q_2} & = w_1 + p (w_2 - w_1)\
              & + left( x_1 + p (x_2 - x_1) right ) ; mathbf{i} \
              & + left( y_1 + p (y_2 - y_1) right ) ; mathbf{j} \
              & + left( z_1 + p (z_2 - z_1) right ) ; mathbf{k}end{align}$$
              if you normalize the result to unit length,
              $$mathbf{q} = frac{w + x' ;mathbf{i} + y' ;mathbf{j} + z' ;mathbf{k}}{sqrt{w'^2 + x'^2 + y'^2 + z'^2}}$$
              This is very useful in camera movement between two orientations. To get a really smooth change, use e.g.
              $$p = 3 p'^2 - 2 p'^3$$
              or
              $$p = 6 p'^5 - 15 p'^4 + 10 p'^3$$
              with $0 le p' le 1$. Both start and stop with zero velocity, but the former has a fixed rate of change of acceleration ("jerk"), and the latter starts and stops with zero acceleration.






              share|cite|improve this answer









              $endgroup$
















                0












                0








                0





                $begingroup$

                If $$mathbf{q_1} = w_1 + x_1mathbf{i} + y_1mathbf{j} + z_1mathbf{k}$$ is an unit quaternion, $$w_1^2 + x_1^2 + y_1^2 + z_1^2 = 1$$representing the first (earlier) rotation, and $$mathbf{q_2} = w_2 + x_2mathbf{i} + y_2mathbf{j} + z_2mathbf{k}$$ is a second (later) rotation, then their Hamilton product represents the combined rotation,
                $$begin{align}mathbf{q} = mathbf{q_2} mathbf{q_1} = ; & w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2\
                + ; & (w_1 x_2 + w_2 x_1 - y_1 z_2 + y_2 z_1) ; mathbf{i}\
                + ; & (w_1 y_2 + w_2 y_1 + x_1 z_2 - x_2 z_1) ; mathbf{j}\
                + ; & (w_1 z_2 + w_2 z_1 - x_1 y_2 + x_2 y_1) ; mathbf{k}
                end{align}$$
                Note that the Hamilton product is not commutative; the order of the quaternions matters. The result is also an unit quaternion, except for any numerical errors that might creep in. Fortunately, you can always normalize the rotation quaternion,
                $$mathbf{q'} = frac{w + x ;mathbf{i} + y ;mathbf{j} + z ;mathbf{k}}{sqrt{w^2 + x^2 + y^2 + z^2}}$$
                to avoid compounding errors. (It is basically safe to do after each operation, but usually necessary only after a few products.)



                The inverse of a rotation is
                $$mathbf{q}^{-1} = w - x ;mathbf{i} - y ;mathbf{j} - z ;mathbf{k}$$
                ie. negating all components of an unit quaternion, except for the scalar component $w$, inverts the rotation. (Negating all components does not change the rotation it represents.)



                You can also interpolate between two unit quaternions, $0 le p le 1$,
                $$begin{align}mathbf{q'} = (1-p)mathbf{q_1} + pmathbf{q_2} & = w_1 + p (w_2 - w_1)\
                & + left( x_1 + p (x_2 - x_1) right ) ; mathbf{i} \
                & + left( y_1 + p (y_2 - y_1) right ) ; mathbf{j} \
                & + left( z_1 + p (z_2 - z_1) right ) ; mathbf{k}end{align}$$
                if you normalize the result to unit length,
                $$mathbf{q} = frac{w + x' ;mathbf{i} + y' ;mathbf{j} + z' ;mathbf{k}}{sqrt{w'^2 + x'^2 + y'^2 + z'^2}}$$
                This is very useful in camera movement between two orientations. To get a really smooth change, use e.g.
                $$p = 3 p'^2 - 2 p'^3$$
                or
                $$p = 6 p'^5 - 15 p'^4 + 10 p'^3$$
                with $0 le p' le 1$. Both start and stop with zero velocity, but the former has a fixed rate of change of acceleration ("jerk"), and the latter starts and stops with zero acceleration.






                share|cite|improve this answer









                $endgroup$



                If $$mathbf{q_1} = w_1 + x_1mathbf{i} + y_1mathbf{j} + z_1mathbf{k}$$ is an unit quaternion, $$w_1^2 + x_1^2 + y_1^2 + z_1^2 = 1$$representing the first (earlier) rotation, and $$mathbf{q_2} = w_2 + x_2mathbf{i} + y_2mathbf{j} + z_2mathbf{k}$$ is a second (later) rotation, then their Hamilton product represents the combined rotation,
                $$begin{align}mathbf{q} = mathbf{q_2} mathbf{q_1} = ; & w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2\
                + ; & (w_1 x_2 + w_2 x_1 - y_1 z_2 + y_2 z_1) ; mathbf{i}\
                + ; & (w_1 y_2 + w_2 y_1 + x_1 z_2 - x_2 z_1) ; mathbf{j}\
                + ; & (w_1 z_2 + w_2 z_1 - x_1 y_2 + x_2 y_1) ; mathbf{k}
                end{align}$$
                Note that the Hamilton product is not commutative; the order of the quaternions matters. The result is also an unit quaternion, except for any numerical errors that might creep in. Fortunately, you can always normalize the rotation quaternion,
                $$mathbf{q'} = frac{w + x ;mathbf{i} + y ;mathbf{j} + z ;mathbf{k}}{sqrt{w^2 + x^2 + y^2 + z^2}}$$
                to avoid compounding errors. (It is basically safe to do after each operation, but usually necessary only after a few products.)



                The inverse of a rotation is
                $$mathbf{q}^{-1} = w - x ;mathbf{i} - y ;mathbf{j} - z ;mathbf{k}$$
                ie. negating all components of an unit quaternion, except for the scalar component $w$, inverts the rotation. (Negating all components does not change the rotation it represents.)



                You can also interpolate between two unit quaternions, $0 le p le 1$,
                $$begin{align}mathbf{q'} = (1-p)mathbf{q_1} + pmathbf{q_2} & = w_1 + p (w_2 - w_1)\
                & + left( x_1 + p (x_2 - x_1) right ) ; mathbf{i} \
                & + left( y_1 + p (y_2 - y_1) right ) ; mathbf{j} \
                & + left( z_1 + p (z_2 - z_1) right ) ; mathbf{k}end{align}$$
                if you normalize the result to unit length,
                $$mathbf{q} = frac{w + x' ;mathbf{i} + y' ;mathbf{j} + z' ;mathbf{k}}{sqrt{w'^2 + x'^2 + y'^2 + z'^2}}$$
                This is very useful in camera movement between two orientations. To get a really smooth change, use e.g.
                $$p = 3 p'^2 - 2 p'^3$$
                or
                $$p = 6 p'^5 - 15 p'^4 + 10 p'^3$$
                with $0 le p' le 1$. Both start and stop with zero velocity, but the former has a fixed rate of change of acceleration ("jerk"), and the latter starts and stops with zero acceleration.







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                answered May 13 '16 at 23:20









                Nominal AnimalNominal Animal

                7,1482617




                7,1482617






























                    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%2f1782243%2fhow-to-calculate-rotation-quaternion-between-two-orientation-quaternions%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

                    Bressuire

                    Cabo Verde

                    Gyllenstierna