Rotate object around a fixed coordinate axis












1












$begingroup$


I am trying to let the user of my app rotate a 3D object drawn in the center of the screen by dragging their finger on screen. A horizontal movement on screen means rotation around a fixed Y axis, and a vertical movement means rotation around the X axis. The problem I am having is that if I just allow rotation around one axis the object rotates fine, but as soon as I introduce a second rotation the object doesn't rotate as expected.



Here is a picture of what is happening:



enter image description here



The blue axis represents my fixed axis. Picture the screen having this fixed blue axis. This is what I want the object to rotate in relation to. What is happening is in red.



Here's what I know:



The first rotation around Y (0, 1, 0) causes the model to move from the blue space (call this space A) into another space (call this space B)
Trying to rotate again using the vector (1, 0, 0) rotates around the x axis in space B NOT in space A which is not what I mean to do.



Here's what I tried to fix this, given what I (think) I know (leaving out the W coord for brevity):




  1. First rotate around Y (0, 1, 0) using a Quaternion.

  2. Convert the rotation Y Quaternion to a Matrix.

  3. Multiply the inverse of the Y rotation matrix by my fixed axis x Vector (1, 0, 0) to get the fixed X axis in relation to the new space.

  4. Rotate around this new X Vector using a Quaternion.


This isn't working how I expect. The rotation seems to work, but at some point horizontal movement doesn't rotate about the Y axis, it appears to rotate about the Z axis.



I'm not sure if my understanding is wrong, or if something else is causing a problem. I have some other transformations I'm doing to the object besides rotation. I move the object to the center before applying rotation. I rotate it using the matrix returned from my function above, then I translate it -2 in the Z direction so I can see the object.










share|cite|improve this question











$endgroup$












  • $begingroup$
    Can you be more specific about how you approach the problem? What exactly are you using?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:14










  • $begingroup$
    @Olivier I posted a more detailed version of the question here
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:18










  • $begingroup$
    Has it not been answered?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:19










  • $begingroup$
    Nope. I've asked on Reddit, Unity Answers, Game Dev stack, and here. No answer, at least not an acceptable one that actually answers my question.
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:20






  • 1




    $begingroup$
    Your nice animation shows 3 rotations, with 9 vectors. Which are X and Y? You should be able to just keep multiplying the object's current quaternion by the new finger-swipe quaternion, and it should work. The problem is unlikely to be in your other transformations. It looks like using a quaternion for step 1 is a waste of time since you could directly get the result of step 2 with a sin and cos. Then steps 3 and 4 seem to be the source of your problem -- rotating around the rotated X axis (red) is exactly what you don't like. Just rotate around the standard X axis (blue).
    $endgroup$
    – Matt
    Mar 18 '15 at 1:08
















1












$begingroup$


I am trying to let the user of my app rotate a 3D object drawn in the center of the screen by dragging their finger on screen. A horizontal movement on screen means rotation around a fixed Y axis, and a vertical movement means rotation around the X axis. The problem I am having is that if I just allow rotation around one axis the object rotates fine, but as soon as I introduce a second rotation the object doesn't rotate as expected.



Here is a picture of what is happening:



enter image description here



The blue axis represents my fixed axis. Picture the screen having this fixed blue axis. This is what I want the object to rotate in relation to. What is happening is in red.



Here's what I know:



The first rotation around Y (0, 1, 0) causes the model to move from the blue space (call this space A) into another space (call this space B)
Trying to rotate again using the vector (1, 0, 0) rotates around the x axis in space B NOT in space A which is not what I mean to do.



Here's what I tried to fix this, given what I (think) I know (leaving out the W coord for brevity):




  1. First rotate around Y (0, 1, 0) using a Quaternion.

  2. Convert the rotation Y Quaternion to a Matrix.

  3. Multiply the inverse of the Y rotation matrix by my fixed axis x Vector (1, 0, 0) to get the fixed X axis in relation to the new space.

  4. Rotate around this new X Vector using a Quaternion.


This isn't working how I expect. The rotation seems to work, but at some point horizontal movement doesn't rotate about the Y axis, it appears to rotate about the Z axis.



I'm not sure if my understanding is wrong, or if something else is causing a problem. I have some other transformations I'm doing to the object besides rotation. I move the object to the center before applying rotation. I rotate it using the matrix returned from my function above, then I translate it -2 in the Z direction so I can see the object.










share|cite|improve this question











$endgroup$












  • $begingroup$
    Can you be more specific about how you approach the problem? What exactly are you using?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:14










  • $begingroup$
    @Olivier I posted a more detailed version of the question here
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:18










  • $begingroup$
    Has it not been answered?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:19










  • $begingroup$
    Nope. I've asked on Reddit, Unity Answers, Game Dev stack, and here. No answer, at least not an acceptable one that actually answers my question.
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:20






  • 1




    $begingroup$
    Your nice animation shows 3 rotations, with 9 vectors. Which are X and Y? You should be able to just keep multiplying the object's current quaternion by the new finger-swipe quaternion, and it should work. The problem is unlikely to be in your other transformations. It looks like using a quaternion for step 1 is a waste of time since you could directly get the result of step 2 with a sin and cos. Then steps 3 and 4 seem to be the source of your problem -- rotating around the rotated X axis (red) is exactly what you don't like. Just rotate around the standard X axis (blue).
    $endgroup$
    – Matt
    Mar 18 '15 at 1:08














1












1








1


1



$begingroup$


I am trying to let the user of my app rotate a 3D object drawn in the center of the screen by dragging their finger on screen. A horizontal movement on screen means rotation around a fixed Y axis, and a vertical movement means rotation around the X axis. The problem I am having is that if I just allow rotation around one axis the object rotates fine, but as soon as I introduce a second rotation the object doesn't rotate as expected.



Here is a picture of what is happening:



enter image description here



The blue axis represents my fixed axis. Picture the screen having this fixed blue axis. This is what I want the object to rotate in relation to. What is happening is in red.



Here's what I know:



The first rotation around Y (0, 1, 0) causes the model to move from the blue space (call this space A) into another space (call this space B)
Trying to rotate again using the vector (1, 0, 0) rotates around the x axis in space B NOT in space A which is not what I mean to do.



Here's what I tried to fix this, given what I (think) I know (leaving out the W coord for brevity):




  1. First rotate around Y (0, 1, 0) using a Quaternion.

  2. Convert the rotation Y Quaternion to a Matrix.

  3. Multiply the inverse of the Y rotation matrix by my fixed axis x Vector (1, 0, 0) to get the fixed X axis in relation to the new space.

  4. Rotate around this new X Vector using a Quaternion.


This isn't working how I expect. The rotation seems to work, but at some point horizontal movement doesn't rotate about the Y axis, it appears to rotate about the Z axis.



I'm not sure if my understanding is wrong, or if something else is causing a problem. I have some other transformations I'm doing to the object besides rotation. I move the object to the center before applying rotation. I rotate it using the matrix returned from my function above, then I translate it -2 in the Z direction so I can see the object.










share|cite|improve this question











$endgroup$




I am trying to let the user of my app rotate a 3D object drawn in the center of the screen by dragging their finger on screen. A horizontal movement on screen means rotation around a fixed Y axis, and a vertical movement means rotation around the X axis. The problem I am having is that if I just allow rotation around one axis the object rotates fine, but as soon as I introduce a second rotation the object doesn't rotate as expected.



Here is a picture of what is happening:



enter image description here



The blue axis represents my fixed axis. Picture the screen having this fixed blue axis. This is what I want the object to rotate in relation to. What is happening is in red.



Here's what I know:



The first rotation around Y (0, 1, 0) causes the model to move from the blue space (call this space A) into another space (call this space B)
Trying to rotate again using the vector (1, 0, 0) rotates around the x axis in space B NOT in space A which is not what I mean to do.



Here's what I tried to fix this, given what I (think) I know (leaving out the W coord for brevity):




  1. First rotate around Y (0, 1, 0) using a Quaternion.

  2. Convert the rotation Y Quaternion to a Matrix.

  3. Multiply the inverse of the Y rotation matrix by my fixed axis x Vector (1, 0, 0) to get the fixed X axis in relation to the new space.

  4. Rotate around this new X Vector using a Quaternion.


This isn't working how I expect. The rotation seems to work, but at some point horizontal movement doesn't rotate about the Y axis, it appears to rotate about the Z axis.



I'm not sure if my understanding is wrong, or if something else is causing a problem. I have some other transformations I'm doing to the object besides rotation. I move the object to the center before applying rotation. I rotate it using the matrix returned from my function above, then I translate it -2 in the Z direction so I can see the object.







linear-algebra 3d rotations






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Mar 18 '15 at 7:40









Daniel Fischer

173k16163285




173k16163285










asked Mar 6 '15 at 18:06









Christopher PerryChristopher Perry

7610




7610












  • $begingroup$
    Can you be more specific about how you approach the problem? What exactly are you using?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:14










  • $begingroup$
    @Olivier I posted a more detailed version of the question here
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:18










  • $begingroup$
    Has it not been answered?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:19










  • $begingroup$
    Nope. I've asked on Reddit, Unity Answers, Game Dev stack, and here. No answer, at least not an acceptable one that actually answers my question.
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:20






  • 1




    $begingroup$
    Your nice animation shows 3 rotations, with 9 vectors. Which are X and Y? You should be able to just keep multiplying the object's current quaternion by the new finger-swipe quaternion, and it should work. The problem is unlikely to be in your other transformations. It looks like using a quaternion for step 1 is a waste of time since you could directly get the result of step 2 with a sin and cos. Then steps 3 and 4 seem to be the source of your problem -- rotating around the rotated X axis (red) is exactly what you don't like. Just rotate around the standard X axis (blue).
    $endgroup$
    – Matt
    Mar 18 '15 at 1:08


















  • $begingroup$
    Can you be more specific about how you approach the problem? What exactly are you using?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:14










  • $begingroup$
    @Olivier I posted a more detailed version of the question here
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:18










  • $begingroup$
    Has it not been answered?
    $endgroup$
    – Olivier
    Mar 13 '15 at 19:19










  • $begingroup$
    Nope. I've asked on Reddit, Unity Answers, Game Dev stack, and here. No answer, at least not an acceptable one that actually answers my question.
    $endgroup$
    – Christopher Perry
    Mar 13 '15 at 19:20






  • 1




    $begingroup$
    Your nice animation shows 3 rotations, with 9 vectors. Which are X and Y? You should be able to just keep multiplying the object's current quaternion by the new finger-swipe quaternion, and it should work. The problem is unlikely to be in your other transformations. It looks like using a quaternion for step 1 is a waste of time since you could directly get the result of step 2 with a sin and cos. Then steps 3 and 4 seem to be the source of your problem -- rotating around the rotated X axis (red) is exactly what you don't like. Just rotate around the standard X axis (blue).
    $endgroup$
    – Matt
    Mar 18 '15 at 1:08
















$begingroup$
Can you be more specific about how you approach the problem? What exactly are you using?
$endgroup$
– Olivier
Mar 13 '15 at 19:14




$begingroup$
Can you be more specific about how you approach the problem? What exactly are you using?
$endgroup$
– Olivier
Mar 13 '15 at 19:14












$begingroup$
@Olivier I posted a more detailed version of the question here
$endgroup$
– Christopher Perry
Mar 13 '15 at 19:18




$begingroup$
@Olivier I posted a more detailed version of the question here
$endgroup$
– Christopher Perry
Mar 13 '15 at 19:18












$begingroup$
Has it not been answered?
$endgroup$
– Olivier
Mar 13 '15 at 19:19




$begingroup$
Has it not been answered?
$endgroup$
– Olivier
Mar 13 '15 at 19:19












$begingroup$
Nope. I've asked on Reddit, Unity Answers, Game Dev stack, and here. No answer, at least not an acceptable one that actually answers my question.
$endgroup$
– Christopher Perry
Mar 13 '15 at 19:20




$begingroup$
Nope. I've asked on Reddit, Unity Answers, Game Dev stack, and here. No answer, at least not an acceptable one that actually answers my question.
$endgroup$
– Christopher Perry
Mar 13 '15 at 19:20




1




1




$begingroup$
Your nice animation shows 3 rotations, with 9 vectors. Which are X and Y? You should be able to just keep multiplying the object's current quaternion by the new finger-swipe quaternion, and it should work. The problem is unlikely to be in your other transformations. It looks like using a quaternion for step 1 is a waste of time since you could directly get the result of step 2 with a sin and cos. Then steps 3 and 4 seem to be the source of your problem -- rotating around the rotated X axis (red) is exactly what you don't like. Just rotate around the standard X axis (blue).
$endgroup$
– Matt
Mar 18 '15 at 1:08




$begingroup$
Your nice animation shows 3 rotations, with 9 vectors. Which are X and Y? You should be able to just keep multiplying the object's current quaternion by the new finger-swipe quaternion, and it should work. The problem is unlikely to be in your other transformations. It looks like using a quaternion for step 1 is a waste of time since you could directly get the result of step 2 with a sin and cos. Then steps 3 and 4 seem to be the source of your problem -- rotating around the rotated X axis (red) is exactly what you don't like. Just rotate around the standard X axis (blue).
$endgroup$
– Matt
Mar 18 '15 at 1:08










1 Answer
1






active

oldest

votes


















0












$begingroup$

I think your problem is related to frame of reference. Your global frame is A and other frames obtained after rotation in A are local frames (such as B). So u want all your rotations in global frame but they are taking place in local frame. For rotation in global frame of reference you need to pre-multiply the transformation matrix and for rotation in local frame, post-multiply. For eg, if u want rotation by $theta_1$ in A for which transformation matrix is $R_{theta_1}$ and then rotation by $theta_2$ in A (rotation matrix $R_{theta_2}$), then:
$$V_f = R_{theta_2}*R_{theta_1}*V_i$$
where $V_i$ is initial position of the point(or object) and $V_f$ is final.
for further reference, check this link:
Maths - frame-of-reference for combining rotations






share|cite|improve this answer









$endgroup$













    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%2f1178558%2frotate-object-around-a-fixed-coordinate-axis%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$

    I think your problem is related to frame of reference. Your global frame is A and other frames obtained after rotation in A are local frames (such as B). So u want all your rotations in global frame but they are taking place in local frame. For rotation in global frame of reference you need to pre-multiply the transformation matrix and for rotation in local frame, post-multiply. For eg, if u want rotation by $theta_1$ in A for which transformation matrix is $R_{theta_1}$ and then rotation by $theta_2$ in A (rotation matrix $R_{theta_2}$), then:
    $$V_f = R_{theta_2}*R_{theta_1}*V_i$$
    where $V_i$ is initial position of the point(or object) and $V_f$ is final.
    for further reference, check this link:
    Maths - frame-of-reference for combining rotations






    share|cite|improve this answer









    $endgroup$


















      0












      $begingroup$

      I think your problem is related to frame of reference. Your global frame is A and other frames obtained after rotation in A are local frames (such as B). So u want all your rotations in global frame but they are taking place in local frame. For rotation in global frame of reference you need to pre-multiply the transformation matrix and for rotation in local frame, post-multiply. For eg, if u want rotation by $theta_1$ in A for which transformation matrix is $R_{theta_1}$ and then rotation by $theta_2$ in A (rotation matrix $R_{theta_2}$), then:
      $$V_f = R_{theta_2}*R_{theta_1}*V_i$$
      where $V_i$ is initial position of the point(or object) and $V_f$ is final.
      for further reference, check this link:
      Maths - frame-of-reference for combining rotations






      share|cite|improve this answer









      $endgroup$
















        0












        0








        0





        $begingroup$

        I think your problem is related to frame of reference. Your global frame is A and other frames obtained after rotation in A are local frames (such as B). So u want all your rotations in global frame but they are taking place in local frame. For rotation in global frame of reference you need to pre-multiply the transformation matrix and for rotation in local frame, post-multiply. For eg, if u want rotation by $theta_1$ in A for which transformation matrix is $R_{theta_1}$ and then rotation by $theta_2$ in A (rotation matrix $R_{theta_2}$), then:
        $$V_f = R_{theta_2}*R_{theta_1}*V_i$$
        where $V_i$ is initial position of the point(or object) and $V_f$ is final.
        for further reference, check this link:
        Maths - frame-of-reference for combining rotations






        share|cite|improve this answer









        $endgroup$



        I think your problem is related to frame of reference. Your global frame is A and other frames obtained after rotation in A are local frames (such as B). So u want all your rotations in global frame but they are taking place in local frame. For rotation in global frame of reference you need to pre-multiply the transformation matrix and for rotation in local frame, post-multiply. For eg, if u want rotation by $theta_1$ in A for which transformation matrix is $R_{theta_1}$ and then rotation by $theta_2$ in A (rotation matrix $R_{theta_2}$), then:
        $$V_f = R_{theta_2}*R_{theta_1}*V_i$$
        where $V_i$ is initial position of the point(or object) and $V_f$ is final.
        for further reference, check this link:
        Maths - frame-of-reference for combining rotations







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Mar 18 '15 at 6:31









        megamindmegamind

        714




        714






























            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%2f1178558%2frotate-object-around-a-fixed-coordinate-axis%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

            Plaza Victoria

            Puebla de Zaragoza

            Musa