Circular Collision Detection
Author |
Message |
B-Man 31
|
Posted: Mon Nov 02, 2009 7:56 pm Post subject: Circular Collision Detection |
|
|
ok, i am trying to make balls bounce off each other, and i can understand who to detect if they collide, whoever, after looking at the tutorials on this website, i dont quite get the math behind calculating the angle when 2 or more balls collide, if anyone would care to explain this, i know trig and i understand that its involved.
for exmaple, after looking at this submission/tutorial i still have some trouble understanding the math behind it. so again, if someone could explain this with as much detail as possible, it would be appreciated |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Mon Nov 02, 2009 8:24 pm Post subject: RE:Circular Collision Detection |
|
|
Well, that is a very complicated way to do it. It requires a basic (or perhaps advanced- I don't know) understanding of vectors. |
|
|
|
|
|
B-Man 31
|
Posted: Mon Nov 02, 2009 9:26 pm Post subject: Re: Circular Collision Detection |
|
|
im gonna ask if this code works/ makes sense. it seems to be working, also i know the basics of vectors
Turing: | proc detectBall
for i : 1 .. ballNum
for o : 1 .. ballNum
if o ~ = i then
if ball (i ).shown = true then
if Math.Distance (ball (i ).x, ball (i ).y, ball (o ).x, ball (o ).y ) < ball_rad then
angle := arctand ((ball (o ).y - ball (i ).y ) / ((ball (o ).x - ball (i ).x )))
temp_x := cosd (angle )
temp_y := sind (angle )
ball (i ).xsp := ball (i ).xsp - (temp_x )
ball (i ).ysp := ball (i ).ysp - (temp_y )
ball (o ).xsp := ball (o ).xsp + (temp_x )
ball (o ).ysp := ball (o ).ysp + (temp_y )
end if
end if
end if
end for
end for
end detectBall
|
|
|
|
|
|
|
bbi5291
|
Posted: Tue Nov 03, 2009 12:43 am Post subject: Re: Circular Collision Detection |
|
|
B-Man 31 @ Mon Nov 02, 2009 9:26 pm wrote: im gonna ask if this code works/ makes sense. it seems to be working, also i know the basics of vectors
Turing: | proc detectBall
for i : 1 .. ballNum
for o : 1 .. ballNum
if o ~ = i then
if ball (i ).shown = true then
if Math.Distance (ball (i ).x, ball (i ).y, ball (o ).x, ball (o ).y ) < ball_rad then
angle := arctand ((ball (o ).y - ball (i ).y ) / ((ball (o ).x - ball (i ).x )))
temp_x := cosd (angle )
temp_y := sind (angle )
ball (i ).xsp := ball (i ).xsp - (temp_x )
ball (i ).ysp := ball (i ).ysp - (temp_y )
ball (o ).xsp := ball (o ).xsp + (temp_x )
ball (o ).ysp := ball (o ).ysp + (temp_y )
end if
end if
end if
end for
end for
end detectBall
|
Looks to me like you're essentially applying force along the axis joining the two circles, which is a crude approximation of what actually happens. But when you say "it seems to be working"... I ask, what happens to the kinetic energy of the balls? A properly designed simulation will address this question by setting or randomly selecting some coefficient of restitution. Simply adding a vector of length 1 to a colliding particle's velocity in every single collision is not physically realistic. Have you tried running the whole simulation, or have you just looked at individual collisions? |
|
|
|
|
|
B-Man 31
|
Posted: Tue Nov 03, 2009 9:25 am Post subject: RE:Circular Collision Detection |
|
|
ive tried running the whole thing, its for a brick game where one of the item drops give you multiple balls, so i dont need any transfer of energy since there is no need for such extreme realism. Would you have a better way of doing this, cuz if so, please do explain. |
|
|
|
|
|
bbi5291
|
Posted: Tue Nov 03, 2009 8:08 pm Post subject: Re: RE:Circular Collision Detection |
|
|
B-Man 31 @ Tue Nov 03, 2009 9:25 am wrote: ive tried running the whole thing, its for a brick game where one of the item drops give you multiple balls, so i dont need any transfer of energy since there is no need for such extreme realism. Would you have a better way of doing this, cuz if so, please do explain. My only concern here is that the way in which kinetic energy changes over time determines what happens, in a general sense, to the balls' speed over time: if it tends to increase over time, for example, the balls will get faster and faster without limit; if it decreases too rapidly, the balls will bounce only a few times before stopping. However, if the balls are automatically destroyed after a short period of time, you shouldn't have any serious problems with the code you have written. |
|
|
|
|
|
B-Man 31
|
Posted: Wed Nov 04, 2009 11:37 am Post subject: RE:Circular Collision Detection |
|
|
ok, i carefully went over it, it isn't working, so if someone could help me with it, it would be really appreciated. another way of solving this problem, no matter how many methods i try, it doesnt seem to work. |
|
|
|
|
|
Kharybdis
|
Posted: Wed Nov 04, 2009 3:10 pm Post subject: RE:Circular Collision Detection |
|
|
The thinking method for a simple way of doing this is:
Define your circle (radius, w/e)
If the outer limit of your circle (the farthest point from the radius) overlaps or equals to the farthest point of another circle, you have a collision and you should assign the circle to not ever go past that point. This is a highly inefficient, but simple method. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
S_Grimm
|
Posted: Wed Nov 04, 2009 4:39 pm Post subject: Re: RE:Circular Collision Detection |
|
|
Kharybdis @ Wed Nov 04, 2009 3:10 pm wrote: The thinking method for a simple way of doing this is:
Define your circle (radius, w/e)
If the outer limit of your circle (the farthest point from the radius) overlaps or equals to the farthest point of another circle, you have a collision and you should assign the circle to not ever go past that point. This is a highly inefficient, but simple method.
it also leads to choppy animations, horrible habits and all around ppp.
i agree with bbi5291. if your balls are getting destroyed at periodic intervals then you won't have many problems |
|
|
|
|
|
B-Man 31
|
Posted: Thu Nov 05, 2009 9:06 am Post subject: RE:Circular Collision Detection |
|
|
yes, but the code is not working, i was hoping someone could tell me why or what am i doing wrong with it. |
|
|
|
|
|
|
|