Calculate bounce velocity vector of an object colliding with a moving object












0














I'm making a 2D game where a ball collides with an obstacle.
The ball has a velocity V. When it collides with the obstacle the impact normal vector is iN. I managed to make the ball bounce off the obstacle with the following calculations:




  1. dotProduct = V.x * iN.x + V.y * iN.y

  2. V.x = V.x + 2 * (iN.x * dotProduct)

  3. V.y = V.y + 2 * (iN.y * dotProduct)


So when doing this the ball bounces fine with it's new velocity, now I can't really figure out how to do the same when the obstacle is moving, here is an image to showcase the issue:



enter image description here



In the above picture OV is the velocity of the obstacle, my guess was to add OV to the new velocity but it didn't work quite well, is it a valid solution and the error comes from my program ?










share|cite|improve this question



























    0














    I'm making a 2D game where a ball collides with an obstacle.
    The ball has a velocity V. When it collides with the obstacle the impact normal vector is iN. I managed to make the ball bounce off the obstacle with the following calculations:




    1. dotProduct = V.x * iN.x + V.y * iN.y

    2. V.x = V.x + 2 * (iN.x * dotProduct)

    3. V.y = V.y + 2 * (iN.y * dotProduct)


    So when doing this the ball bounces fine with it's new velocity, now I can't really figure out how to do the same when the obstacle is moving, here is an image to showcase the issue:



    enter image description here



    In the above picture OV is the velocity of the obstacle, my guess was to add OV to the new velocity but it didn't work quite well, is it a valid solution and the error comes from my program ?










    share|cite|improve this question

























      0












      0








      0







      I'm making a 2D game where a ball collides with an obstacle.
      The ball has a velocity V. When it collides with the obstacle the impact normal vector is iN. I managed to make the ball bounce off the obstacle with the following calculations:




      1. dotProduct = V.x * iN.x + V.y * iN.y

      2. V.x = V.x + 2 * (iN.x * dotProduct)

      3. V.y = V.y + 2 * (iN.y * dotProduct)


      So when doing this the ball bounces fine with it's new velocity, now I can't really figure out how to do the same when the obstacle is moving, here is an image to showcase the issue:



      enter image description here



      In the above picture OV is the velocity of the obstacle, my guess was to add OV to the new velocity but it didn't work quite well, is it a valid solution and the error comes from my program ?










      share|cite|improve this question













      I'm making a 2D game where a ball collides with an obstacle.
      The ball has a velocity V. When it collides with the obstacle the impact normal vector is iN. I managed to make the ball bounce off the obstacle with the following calculations:




      1. dotProduct = V.x * iN.x + V.y * iN.y

      2. V.x = V.x + 2 * (iN.x * dotProduct)

      3. V.y = V.y + 2 * (iN.y * dotProduct)


      So when doing this the ball bounces fine with it's new velocity, now I can't really figure out how to do the same when the obstacle is moving, here is an image to showcase the issue:



      enter image description here



      In the above picture OV is the velocity of the obstacle, my guess was to add OV to the new velocity but it didn't work quite well, is it a valid solution and the error comes from my program ?







      vectors






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Jan 4 at 13:29









      MattMatt

      133




      133






















          2 Answers
          2






          active

          oldest

          votes


















          0














          This might be better suited for the physics page. That said you should move to a reference frame where the wall is not moving, do the calculation there, and move back.



          To move to the reference frame where the wall is not moving, we need to subtract away the velocity of the wall for everything. Now the wall's velocity is zero and the ball has a "new" velocity $v' = (v - ov)$. You can then do the calculation as if the wall were stationary, and then move back to the original reference frame (add the velocity of the wall back).



          Note that whey I say add/subtract the velocity of the wall that I mean the velocity as a vector. If your wall is only moving in the $x$ direction, then you only need to adjust the $x$-coordinate.






          share|cite|improve this answer





















          • Thanks it was quite easy to implement in my case and worked really well
            – Matt
            Jan 4 at 15:41



















          0














          If the object moves with velocity $vec v_0$ the ball with velocity $vec v$ and the normal at the impact point is $vec n$ then we have:



          $$
          vec v = vec v_{vec n}+vec v_{Pi}\
          vec v_{Pi} = vec v - vec v_{vec n_1} \
          vec v_r = (vec v-vec v_0)_{Pi}-(vec v-vec v_0)_{vec n}\
          vec v_r = (vec v-vec v_0) -2((vec v-vec v_0).vec v_{vec n})vec v_{vec n}
          $$



          with



          $$
          vec v_{vec n} = left(vec vcdotleft(frac{vec n}{||vec n||}right)right)frac{vec n}{||vec n||}
          $$



          where $vec v_r$ represents the reflected ball velocity after collision



          NOTE



          Here $Pi$ represents the plane passing by the impact point with normal $vec n$



          Attached three cases. Here



          $$
          begin{cases}
          vec v mbox{red}\
          vec v_0 mbox{green}\
          vec n mbox{black}\
          Pi mbox{dashed cyan}\
          vec v_r mbox{blue}
          end{cases}
          $$



          enter image description hereenter image description hereenter image description here






          share|cite|improve this answer























          • What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
            – Matt
            Jan 4 at 15:06










          • @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
            – Cesareo
            Jan 4 at 15:10










          • Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
            – Matt
            Jan 4 at 15:42










          • @Matt Some results attached.
            – Cesareo
            Jan 4 at 19:17











          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%2f3061653%2fcalculate-bounce-velocity-vector-of-an-object-colliding-with-a-moving-object%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          This might be better suited for the physics page. That said you should move to a reference frame where the wall is not moving, do the calculation there, and move back.



          To move to the reference frame where the wall is not moving, we need to subtract away the velocity of the wall for everything. Now the wall's velocity is zero and the ball has a "new" velocity $v' = (v - ov)$. You can then do the calculation as if the wall were stationary, and then move back to the original reference frame (add the velocity of the wall back).



          Note that whey I say add/subtract the velocity of the wall that I mean the velocity as a vector. If your wall is only moving in the $x$ direction, then you only need to adjust the $x$-coordinate.






          share|cite|improve this answer





















          • Thanks it was quite easy to implement in my case and worked really well
            – Matt
            Jan 4 at 15:41
















          0














          This might be better suited for the physics page. That said you should move to a reference frame where the wall is not moving, do the calculation there, and move back.



          To move to the reference frame where the wall is not moving, we need to subtract away the velocity of the wall for everything. Now the wall's velocity is zero and the ball has a "new" velocity $v' = (v - ov)$. You can then do the calculation as if the wall were stationary, and then move back to the original reference frame (add the velocity of the wall back).



          Note that whey I say add/subtract the velocity of the wall that I mean the velocity as a vector. If your wall is only moving in the $x$ direction, then you only need to adjust the $x$-coordinate.






          share|cite|improve this answer





















          • Thanks it was quite easy to implement in my case and worked really well
            – Matt
            Jan 4 at 15:41














          0












          0








          0






          This might be better suited for the physics page. That said you should move to a reference frame where the wall is not moving, do the calculation there, and move back.



          To move to the reference frame where the wall is not moving, we need to subtract away the velocity of the wall for everything. Now the wall's velocity is zero and the ball has a "new" velocity $v' = (v - ov)$. You can then do the calculation as if the wall were stationary, and then move back to the original reference frame (add the velocity of the wall back).



          Note that whey I say add/subtract the velocity of the wall that I mean the velocity as a vector. If your wall is only moving in the $x$ direction, then you only need to adjust the $x$-coordinate.






          share|cite|improve this answer












          This might be better suited for the physics page. That said you should move to a reference frame where the wall is not moving, do the calculation there, and move back.



          To move to the reference frame where the wall is not moving, we need to subtract away the velocity of the wall for everything. Now the wall's velocity is zero and the ball has a "new" velocity $v' = (v - ov)$. You can then do the calculation as if the wall were stationary, and then move back to the original reference frame (add the velocity of the wall back).



          Note that whey I say add/subtract the velocity of the wall that I mean the velocity as a vector. If your wall is only moving in the $x$ direction, then you only need to adjust the $x$-coordinate.







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Jan 4 at 14:37









          tchtch

          639210




          639210












          • Thanks it was quite easy to implement in my case and worked really well
            – Matt
            Jan 4 at 15:41


















          • Thanks it was quite easy to implement in my case and worked really well
            – Matt
            Jan 4 at 15:41
















          Thanks it was quite easy to implement in my case and worked really well
          – Matt
          Jan 4 at 15:41




          Thanks it was quite easy to implement in my case and worked really well
          – Matt
          Jan 4 at 15:41











          0














          If the object moves with velocity $vec v_0$ the ball with velocity $vec v$ and the normal at the impact point is $vec n$ then we have:



          $$
          vec v = vec v_{vec n}+vec v_{Pi}\
          vec v_{Pi} = vec v - vec v_{vec n_1} \
          vec v_r = (vec v-vec v_0)_{Pi}-(vec v-vec v_0)_{vec n}\
          vec v_r = (vec v-vec v_0) -2((vec v-vec v_0).vec v_{vec n})vec v_{vec n}
          $$



          with



          $$
          vec v_{vec n} = left(vec vcdotleft(frac{vec n}{||vec n||}right)right)frac{vec n}{||vec n||}
          $$



          where $vec v_r$ represents the reflected ball velocity after collision



          NOTE



          Here $Pi$ represents the plane passing by the impact point with normal $vec n$



          Attached three cases. Here



          $$
          begin{cases}
          vec v mbox{red}\
          vec v_0 mbox{green}\
          vec n mbox{black}\
          Pi mbox{dashed cyan}\
          vec v_r mbox{blue}
          end{cases}
          $$



          enter image description hereenter image description hereenter image description here






          share|cite|improve this answer























          • What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
            – Matt
            Jan 4 at 15:06










          • @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
            – Cesareo
            Jan 4 at 15:10










          • Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
            – Matt
            Jan 4 at 15:42










          • @Matt Some results attached.
            – Cesareo
            Jan 4 at 19:17
















          0














          If the object moves with velocity $vec v_0$ the ball with velocity $vec v$ and the normal at the impact point is $vec n$ then we have:



          $$
          vec v = vec v_{vec n}+vec v_{Pi}\
          vec v_{Pi} = vec v - vec v_{vec n_1} \
          vec v_r = (vec v-vec v_0)_{Pi}-(vec v-vec v_0)_{vec n}\
          vec v_r = (vec v-vec v_0) -2((vec v-vec v_0).vec v_{vec n})vec v_{vec n}
          $$



          with



          $$
          vec v_{vec n} = left(vec vcdotleft(frac{vec n}{||vec n||}right)right)frac{vec n}{||vec n||}
          $$



          where $vec v_r$ represents the reflected ball velocity after collision



          NOTE



          Here $Pi$ represents the plane passing by the impact point with normal $vec n$



          Attached three cases. Here



          $$
          begin{cases}
          vec v mbox{red}\
          vec v_0 mbox{green}\
          vec n mbox{black}\
          Pi mbox{dashed cyan}\
          vec v_r mbox{blue}
          end{cases}
          $$



          enter image description hereenter image description hereenter image description here






          share|cite|improve this answer























          • What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
            – Matt
            Jan 4 at 15:06










          • @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
            – Cesareo
            Jan 4 at 15:10










          • Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
            – Matt
            Jan 4 at 15:42










          • @Matt Some results attached.
            – Cesareo
            Jan 4 at 19:17














          0












          0








          0






          If the object moves with velocity $vec v_0$ the ball with velocity $vec v$ and the normal at the impact point is $vec n$ then we have:



          $$
          vec v = vec v_{vec n}+vec v_{Pi}\
          vec v_{Pi} = vec v - vec v_{vec n_1} \
          vec v_r = (vec v-vec v_0)_{Pi}-(vec v-vec v_0)_{vec n}\
          vec v_r = (vec v-vec v_0) -2((vec v-vec v_0).vec v_{vec n})vec v_{vec n}
          $$



          with



          $$
          vec v_{vec n} = left(vec vcdotleft(frac{vec n}{||vec n||}right)right)frac{vec n}{||vec n||}
          $$



          where $vec v_r$ represents the reflected ball velocity after collision



          NOTE



          Here $Pi$ represents the plane passing by the impact point with normal $vec n$



          Attached three cases. Here



          $$
          begin{cases}
          vec v mbox{red}\
          vec v_0 mbox{green}\
          vec n mbox{black}\
          Pi mbox{dashed cyan}\
          vec v_r mbox{blue}
          end{cases}
          $$



          enter image description hereenter image description hereenter image description here






          share|cite|improve this answer














          If the object moves with velocity $vec v_0$ the ball with velocity $vec v$ and the normal at the impact point is $vec n$ then we have:



          $$
          vec v = vec v_{vec n}+vec v_{Pi}\
          vec v_{Pi} = vec v - vec v_{vec n_1} \
          vec v_r = (vec v-vec v_0)_{Pi}-(vec v-vec v_0)_{vec n}\
          vec v_r = (vec v-vec v_0) -2((vec v-vec v_0).vec v_{vec n})vec v_{vec n}
          $$



          with



          $$
          vec v_{vec n} = left(vec vcdotleft(frac{vec n}{||vec n||}right)right)frac{vec n}{||vec n||}
          $$



          where $vec v_r$ represents the reflected ball velocity after collision



          NOTE



          Here $Pi$ represents the plane passing by the impact point with normal $vec n$



          Attached three cases. Here



          $$
          begin{cases}
          vec v mbox{red}\
          vec v_0 mbox{green}\
          vec n mbox{black}\
          Pi mbox{dashed cyan}\
          vec v_r mbox{blue}
          end{cases}
          $$



          enter image description hereenter image description hereenter image description here







          share|cite|improve this answer














          share|cite|improve this answer



          share|cite|improve this answer








          edited Jan 4 at 19:13

























          answered Jan 4 at 14:26









          CesareoCesareo

          8,3413516




          8,3413516












          • What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
            – Matt
            Jan 4 at 15:06










          • @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
            – Cesareo
            Jan 4 at 15:10










          • Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
            – Matt
            Jan 4 at 15:42










          • @Matt Some results attached.
            – Cesareo
            Jan 4 at 19:17


















          • What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
            – Matt
            Jan 4 at 15:06










          • @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
            – Cesareo
            Jan 4 at 15:10










          • Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
            – Matt
            Jan 4 at 15:42










          • @Matt Some results attached.
            – Cesareo
            Jan 4 at 19:17
















          What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
          – Matt
          Jan 4 at 15:06




          What are (v⃗ 0)n⃗ and (v⃗ 0)Π ? This is probably a notation i'm not aware of
          – Matt
          Jan 4 at 15:06












          @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
          – Cesareo
          Jan 4 at 15:10




          @Matt Are the components of $vec v_0$ regarding $vec n$ and $Pi$ They are calculated in the same way as $vec v_{vec n}$ and $vec v_{Pi}$
          – Cesareo
          Jan 4 at 15:10












          Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
          – Matt
          Jan 4 at 15:42




          Thank you for the time you took to answer, however your answer didn't really help me, the answer below worked fine.
          – Matt
          Jan 4 at 15:42












          @Matt Some results attached.
          – Cesareo
          Jan 4 at 19:17




          @Matt Some results attached.
          – Cesareo
          Jan 4 at 19:17


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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.


          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%2f3061653%2fcalculate-bounce-velocity-vector-of-an-object-colliding-with-a-moving-object%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

          An IMO inspired problem

          Management

          Investment