Author |
Message |
MichaelM
|
Posted: Fri Jun 27, 2008 10:42 am Post subject: Re: Perfect Circle - Circle Collision Detection |
|
|
Wow Zylum, great tutorial. You've really come up with a great way of doing circle collision detection, which looks complicated, but it all makes so much sense.
However, I'm having a bit of trouble figuring out what you've done for circle collision reaction. I'm a little lost with some of the variables you're using in the collision procedure. Could you, or anyone else who understands it all, tell me whats going on with nx,ny and p. Also, I'm not sure I understand what vxp and vyp are being used for.
code: |
proc collide (var b1, b2 : BallData)
var nx := (b1.x - b2.x) / (b1.r + b2.r)
var ny := (b1.y - b2.y) / (b1.r + b2.r)
var a1 := b1.vx * nx + b1.vy * ny
var a2 := b2.vx * nx + b2.vy * ny
var p := 2 * (a1 - a2) / (b1.m + b2.m)
b1.vxp := b1.vx - p * nx * b2.m
b1.vyp := b1.vy - p * ny * b2.m
b2.vxp := b2.vx + p * nx * b1.m
b2.vyp := b2.vy + p * ny * b1.m
end collide
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Soundman
|
Posted: Tue Jul 29, 2008 4:32 am Post subject: Re: Perfect Circle - Circle Collision Detection |
|
|
code: |
proc collide (var b1, b2 : BallData)
var nx := (b1.x - b2.x) / (b1.r + b2.r) - the normalised vector in the x direction
var ny := (b1.y - b2.y) / (b1.r + b2.r) - the normalised vector in the y direction
var a1 := b1.vx * nx + b1.vy * ny - 1st ball impulse
var a2 := b2.vx * nx + b2.vy * ny - 2nd ball impulse
var p := 2 * (a1 - a2) / (b1.m + b2.m) - resultant impulse
b1.vxp := b1.vx - p * nx * b2.m - ball1 resultant Vx value
b1.vyp := b1.vy - p * ny * b2.m - ball1 resultant Vy value
b2.vxp := b2.vx + p * nx * b1.m - ball2 resultant Vx value
b2.vyp := b2.vy + p * ny * b1.m - ball2 resultant Vy value
end collide
|
|
|
|
|
|
|
Georgey Boy
|
Posted: Thu Nov 13, 2008 3:38 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
Hi, i am working on the same thing in C#...
Great Solutions zylum!!! thank you...helps a lot!!!
So I need help...
I have an array of class Ball...
each ball has PointF positon; PointF vector;
I have timer that ticks...) So each time...
position += vector * time //well it looks different due to PointF class specs...but that what it does
I already figure out how to move balls away from each other in case of collision...
Now I need to figure out vectors after collision...
I am wondering about some vars...
b1.vxp := b1.vx - p * nx * b2.m - ball1 resultant Vx value
b1.vyp := b1.vy - p * ny * b2.m - ball1 resultant Vy value
What is b2.m? is it center or middle or mass? what if mass is the same? or it does not matter?
Also b2.vxp... |
|
|
|
|
|
[Gandalf]
|
Posted: Thu Nov 13, 2008 9:19 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
I believe ball.m is the area of the ball, from a quick glance at the code, since it's initialized to:
code: | Math.PI * balls (i).r ** 2 |
Edit: Oh, as for p, it could be momentum if I'm remembering my physics correctly. Don't quote me on it though!
Edit2: Ah right, it's impulse, change in momentum. Just read the post directly above yours. It's all coming back now. |
|
|
|
|
|
Georgey Boy
|
Posted: Sat Nov 15, 2008 4:09 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
thank you [Gandalf] fo responce...
now I see that mass is just its area...
nevertheless i new what p was...I was wondering about b1.vxp...
Plus I wondering what this code does...is it wall collision?
if balls (i).x < 1 or balls (i).x > maxx then
balls (i).vxp *= -1
end if
if balls (i).y < 1 or balls (i).y > maxy then
balls (i).vyp *= -1
end if |
|
|
|
|
|
SNIPERDUDE
|
Posted: Sat Nov 15, 2008 4:31 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
Yes. |
|
|
|
|
|
S_Grimm
|
Posted: Sat Nov 15, 2008 5:40 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
Great Tutorial.
+Karama |
|
|
|
|
|
DanielG
|
Posted: Sun Nov 16, 2008 10:25 am Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
yes, I might try to implenet it, so far I only used simple circle collision (the bad kind). |
|
|
|
|
|
Sponsor Sponsor
|
|
|
corriep
|
Posted: Tue Nov 25, 2008 5:31 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
WOW, just WOW
great tutorial, +bits
Could you explain the collision procedure.
I tried to follow it but it went way above my head! |
|
|
|
|
|
matt271
|
Posted: Sun Apr 05, 2009 1:45 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
i like ur method, but its pretty complicated.
did u come up w/ this urself??
i have come up w/ my own method i would like to show u and maybe get ur input on.
i posted it here (its in java) http://compsci.ca/v3/viewtopic.php?t=20676 |
|
|
|
|
|
carlessr
|
Posted: Sat Jan 30, 2010 2:49 pm Post subject: Re: Perfect Circle - Circle Collision Detection |
|
|
Fantastic tutorial, however i have a question.
If I were to give one of the circles infinite mass (ie a mass of 0) then the Collision Response function doesn't seem to work.
Is this intentional? |
|
|
|
|
|
SNIPERDUDE
|
Posted: Sat Jan 30, 2010 3:21 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
What wins: an unstoppable force, or an unmovable object?
How can one determine the physics of an object with no defined mass? Even if we say it is extremely minute, or extremely large values, they are still given values. |
|
|
|
|
|
carlessr
|
Posted: Sun Jan 31, 2010 6:13 am Post subject: Re: Perfect Circle - Circle Collision Detection |
|
|
I take your point.
I was just wondering if I could rearrange the applycollision to zero out a force if the mass was zero. |
|
|
|
|
|
SNIPERDUDE
|
Posted: Sun Jan 31, 2010 3:03 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
You could make an exception perhaps. |
|
|
|
|
|
SNIPERDUDE
|
Posted: Tue Feb 02, 2010 9:37 pm Post subject: RE:Perfect Circle - Circle Collision Detection |
|
|
SPAM. |
|
|
|
|
|
|