Calculate bounce velocity vector of an object colliding with a moving object
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:
- dotProduct = V.x * iN.x + V.y * iN.y
- V.x = V.x + 2 * (iN.x * dotProduct)
- 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:
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
add a comment |
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:
- dotProduct = V.x * iN.x + V.y * iN.y
- V.x = V.x + 2 * (iN.x * dotProduct)
- 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:
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
add a comment |
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:
- dotProduct = V.x * iN.x + V.y * iN.y
- V.x = V.x + 2 * (iN.x * dotProduct)
- 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:
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
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:
- dotProduct = V.x * iN.x + V.y * iN.y
- V.x = V.x + 2 * (iN.x * dotProduct)
- 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:
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
vectors
asked Jan 4 at 13:29
MattMatt
133
133
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
Thanks it was quite easy to implement in my case and worked really well
– Matt
Jan 4 at 15:41
add a comment |
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}
$$
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Thanks it was quite easy to implement in my case and worked really well
– Matt
Jan 4 at 15:41
add a comment |
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.
Thanks it was quite easy to implement in my case and worked really well
– Matt
Jan 4 at 15:41
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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}
$$
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
add a comment |
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}
$$
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
add a comment |
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}
$$
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}
$$
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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