Collision Response Question
Ok, so I need some help with the math of a collision response. The detection part is finished and works properly  but that's the easy part. The following is a diagram:
Basically the ball has a direction vector of Vector A, and it's going to bounce off of the inside of the circle. I understand that it needs to reflect off the vector drawn between the large circle's origin and the point of collision (Vector B), thus becoming Vector C. I think Vector D gets involved somewhere in the calculations  that's why I've included it.
What's the easiest way to do this? Seems a bit complicated, but I'm sure there's an easy solution to this one... Thanks in advance.
Basically the ball has a direction vector of Vector A, and it's going to bounce off of the inside of the circle. I understand that it needs to reflect off the vector drawn between the large circle's origin and the point of collision (Vector B), thus becoming Vector C. I think Vector D gets involved somewhere in the calculations  that's why I've included it.
What's the easiest way to do this? Seems a bit complicated, but I'm sure there's an easy solution to this one... Thanks in advance.
maybe try and implement this with the new rational trigonometry,
http://web.maths.unsw.edu.au/~norman/pap...apter1.pdf
Just a thought, it might make things easier.
http://web.maths.unsw.edu.au/~norman/pap...apter1.pdf
Just a thought, it might make things easier.
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Or more succinctly:
perpendicular = (A â€¢ B) Ã— B
parallel = A â€“ perpendicular
C = parallel Ã— friction + perpendicular Ã— â€“bounce
where friction and bounce > 0 and < 1
and B is a unit vector
perpendicular = (A â€¢ B) Ã— B
parallel = A â€“ perpendicular
C = parallel Ã— friction + perpendicular Ã— â€“bounce
where friction and bounce > 0 and < 1
and B is a unit vector
Ok, the Mathematica page looks great  but very confusing to someone who hasn't taken math courses in 6 years.
Will: that explanation looks decent, but I have to wrap my mind around it for a bit. It's important to me that I *understand* this  makes debugging easier. Assuming there is no friction and the bounce is constant, would I use values of 1.0 for each?
And when you suggest to multiply floats by vectors, do you mean simply to multiply the value by both elements of the vector?
Excuse my math skills, or lack thereof. It's been a long time since high school math, and I find this all a bit confusing.
Will: that explanation looks decent, but I have to wrap my mind around it for a bit. It's important to me that I *understand* this  makes debugging easier. Assuming there is no friction and the bounce is constant, would I use values of 1.0 for each?
And when you suggest to multiply floats by vectors, do you mean simply to multiply the value by both elements of the vector?
Excuse my math skills, or lack thereof. It's been a long time since high school math, and I find this all a bit confusing.
Yes when you multiply vectors by floats just multiply both elements of the vector. A bounce of 1 and the ball never stops bouncing. A bounce greater than 1 and it gets exponentially faster until something goes wrong.
The maths above splits the balls velocity vector into two orthogonal components, one along the vector B perpendicular (pp) to the collision point, and one along the vector D parallel (p) to the collision point. It is easy to then combine these back to get the reflection vector.
The maths above splits the balls velocity vector into two orthogonal components, one along the vector B perpendicular (pp) to the collision point, and one along the vector D parallel (p) to the collision point. It is easy to then combine these back to get the reflection vector.
Wow, thanks Will! Great diagram  what did you use to make it? I grow quickly tired of Sketch.app!
I'll try to implement that tonight.
I'll try to implement that tonight.
I was just reading on this page that the cross product can only be computed for 3D vectors. Since this is 2D space, what does (A â€¢ B) Ã— B mean (how do you calculate it)?
A dot B
the dot product is
a.x*b.x + a.y*b.y
in 3D
a.x*b.x + a.y*b.y + a.z*b.z
an important property is that
a.b/ab = cos (the angle between a and b)
the dot product is
a.x*b.x + a.y*b.y
in 3D
a.x*b.x + a.y*b.y + a.z*b.z
an important property is that
a.b/ab = cos (the angle between a and b)
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
unknown Wrote:A dot B
the dot product is
a.x*b.x + a.y*b.y
in 3D
a.x*b.x + a.y*b.y + a.z*b.z
an important property is that
a.b/ab = cos (the angle between a and b)
But what about the cross product between the resulting scalar and B? Do I just multiply each of B's components by the scalar?
For example, say the dot product turned out to be 3. Would I just stretch each of B's components by a factor of 3?
Quote:But what about the cross product between the resulting scalar and B?You can only do the cross product in 3D.
Quote:Would I just stretch each of B's components by a factor of 3?That would give you (A â€¢ B) x B.
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Technically it is not a cross product. Crossproducts are only between vectors. It is just a multiply. So yes just multiply each of B's components by the scalar. So (A â€¢ B) Ã— B is just: B scaled to the magnitude of the dot product of A and B.
Quote:Wow, thanks Will! Great diagram  what did you use to make it? I grow quickly tired of Sketch.app!thanks. I used Imprint, my newasyetunreleased drawing program. http://will.thimbleby.net/draw If you are interested in betatesting let me know.
my brother just told me it's probably better to write it like (Aâ€¢B)B in order to avoid confusion
Well the x means multiply, and you can also write it like that or * or â€¢, the last one is probably quite confusing if your using it for dot product as well!
Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
ARIGHT! It works! Thanks so much, Will!
Code:
Binary (): http://www.owlnet.rice.edu/~ajm4979/BG.zip
Code:
PHP Code:
/* COLLISION RESPONSE
General mathematical idea:
define vector B as vector from origin through point of collision
D = (A â€¢ B) Ã— B
parallel = A â€“ D
C = parallel + D Ã— â€“bounce */
// Define 1 temporary vector for calculations ...
vector A = [ball direction];
// Calculate the point where the ball is colliding with the play area
vector pointOfCollision = (vector){ ([ball position].x + (A.x * [ball radius])),
([ball position].y + (A.y * [ball radius]))};
// ... continue by defining 3 more temporary Vectors ...
vector B = (vector){ (pointOfCollision.x  250.0), (pointOfCollision.y  250.0) };
B = vectorNormalise(B);
vector D = vectorMultiply(B, vectorDotProduct(A, B));
vector parallel = vectorSubtract(A, D);
// ... and finish by calculating the last "temporary" vector, which is the resulting vector
vector C = vectorAdd(parallel, vectorMultiply(D, BOUNCE));
C = vectorNormalise(C);
// Apply the change to the ball object's direction vector
[ball setDirection:C];
Binary (): http://www.owlnet.rice.edu/~ajm4979/BG.zip
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Collision Response  merrill541  7  4,248 
Nov 8, 2008 09:14 PM Last Post: merrill541 

Edge Collision Response Problem  Bachus  9  7,823 
Mar 21, 2008 03:34 PM Last Post: Skorche 

Simple 2D collision response  Wowbagger  1  5,027 
Jul 30, 2007 03:02 PM Last Post: Skorche 

Collision Response With Circles  Nick  8  4,212 
Nov 3, 2006 04:11 PM Last Post: Skorche 

Yet Another Collision Detection Question  t3knomanser  1  2,516 
Apr 14, 2006 06:46 AM Last Post: codemattic 