Collision Response Question

Member
Posts: 196
Joined: 2003.10
Post: #1
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:

[Image: diagram.png]

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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
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.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 78
Joined: 2002.06
Post: #4
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
Quote this message in a reply
Member
Posts: 196
Joined: 2003.10
Post: #5
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.
Quote this message in a reply
Member
Posts: 78
Joined: 2002.06
Post: #6
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.

[Image: reflection.png]
Quote this message in a reply
Member
Posts: 196
Joined: 2003.10
Post: #7
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.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #8
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)?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #9
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)

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #10
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 this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #11
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!
Quote this message in a reply
Member
Posts: 78
Joined: 2002.06
Post: #12
Technically it is not a cross product. Cross-products 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!
Grin thanks. I used Imprint, my new-as-yet-unreleased drawing program. http://will.thimbleby.net/draw If you are interested in beta-testing let me know.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #13
my brother just told me it's probably better to write it like (A•B)B in order to avoid confusion Wink
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #14
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!
Quote this message in a reply
Member
Posts: 196
Joined: 2003.10
Post: #15
ARIGHT! It works! Thanks so much, Will!

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].+ (A.* [ball radius])),
                                    ([
ball position].+ (A.* [ball radius]))};

// ... continue by defining 3 more temporary Vectors ...
vector B = (vector){ (pointOfCollision.250.0), (pointOfCollision.250.0) };
vectorNormalise(B);

vector D vectorMultiply(BvectorDotProduct(AB));
vector parallel vectorSubtract(AD);

// ... and finish by calculating the last "temporary" vector, which is the resulting vector
vector C vectorAdd(parallelvectorMultiply(D, -BOUNCE));
vectorNormalise(C);

// Apply the change to the ball object's direction vector
[ball setDirection:C]; 

Binary (Wink): http://www.owlnet.rice.edu/~ajm4979/BG.zip
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Collision Response merrill541 7 3,728 Nov 8, 2008 09:14 PM
Last Post: merrill541
  Edge Collision Response Problem Bachus 9 6,386 Mar 21, 2008 03:34 PM
Last Post: Skorche
  Simple 2D collision response Wowbagger 1 4,687 Jul 30, 2007 03:02 PM
Last Post: Skorche
  Collision Response With Circles Nick 8 3,603 Nov 3, 2006 04:11 PM
Last Post: Skorche
  Yet Another Collision Detection Question t3knomanser 1 2,209 Apr 14, 2006 06:46 AM
Last Post: codemattic