
2D ColDet between two moving spheres
I have two 2D circles, both of them moving, and I need to know where they collide (sliding would be nice, too
). Anyone know of any good tutorials to do with this?

If that''s for a 2D game (say... like Stick Soldier), you don''t really need an analytical solution for this. You can move your object by v * dt, and check if there is a collision. To check if there is a collision,
d = distance between sphere A and sphere B
rA, rB = radiuses of sphere A and sphere B
if rA + rB < d, there is no collision
if rA + rB > d, there is a collision, and the collision point is a weigthed average of both centers
P.x = CA.x + (CB.x - CA.x) * rA / (rA + rB)
P.y = CA.y + (CB.y - CA.y) * rA / (rA + rB)
where CA, CB are the center of both spheres
If rA + rB is much larger than d, it means that the spheres are overlapping a lot. In that case, you might want to move your sphere back to its initial position, and try a smaller time step.
Cédric
d = distance between sphere A and sphere B
rA, rB = radiuses of sphere A and sphere B
if rA + rB < d, there is no collision
if rA + rB > d, there is a collision, and the collision point is a weigthed average of both centers
P.x = CA.x + (CB.x - CA.x) * rA / (rA + rB)
P.y = CA.y + (CB.y - CA.y) * rA / (rA + rB)
where CA, CB are the center of both spheres
If rA + rB is much larger than d, it means that the spheres are overlapping a lot. In that case, you might want to move your sphere back to its initial position, and try a smaller time step.
Cédric
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement