2D Collision Physics between Rectangles

Started by
7 comments, last by Nathaniel Hammen 21 years, 4 months ago
You guys probably get this question alot, as it is very important for collisions. That means it should be answered pretty quick. I have two rectangles that are colliding in 2D space. I know the formulas to seperate the force that one apllies on the other into the translational force and the torque using the lever arm, and I know how to use these to calculate the change in velocity. My question is, how do I find this origional force? -------------------------------------- I am the master of stories..... If only I could just write them down...
I am the master of ideas.....If only I could write them down...
Advertisement
Force = mass * acceleration, so you should already know the mass and acceleration of the objects and hence the force they exert. Maybe I am on the wrong track here.
Unfortunately, I don''t know the accleration. I use the force to find the acceleration, but I don''t know the force.

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If only I could write them down...
quote:Original post by Nathaniel Hammen
Unfortunately, I don't know the accleration. I use the force to find the acceleration, but I don't know the force.


The equation for acceleration is a = (vf-vi)/t. Not sure if this is exactly your problem, but if you know the time it takes for them to collide, you could use that equation. However, this would only apply to uniform acceleration...So, you could sub that into the force equation to get F = m((vf-vi)/t)



[edited by - Apocalypse_Demon on December 1, 2002 6:54:43 PM]
A.) The acceleration is not uniform.

B.) I don''t know the time it takes to collide.

C.) I''m using the average acceleration (which also works with that equation) per tick to find the velocity after each tick using the velocity before the tick as the initial velocity. I''m guessing that a collision would last about 5 ticks at 20 ticks per second.

Maybe I should ask for a different way to find final velocity??

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If only I could write them down...
Sounds to me like you are working on collision response and constraints in your 2D rigid body dynamics engine. One way to implement constraints is to introduce some very stiff springs that will pull your bodies apart when a collision are detected and when the bodies move towards each other. The magnitude of this spring force should be propotional to how far the two bodies have travelled into each other. This method of implementing constraints is known as a penalty method. Another way is by using a new quantity called impulses that can change a bodies velocity directly without having to change the acceleration. Other more complex and efficient methods exist like generalized coordinates or lagrange constraints. I suggest looking thru this page about rigid body dynamics. It has a lot of useful resources on collision detection and response.
Yes, I think your best bet is to implement pentalty based dynamics, although doing it that way forces you to find intersection _areas_ of the two objects, and the normal of the collision is not totally clear. The other way to do this is to find the collision point before the two objects actually collide, which requires a bunch of vector equations plus a quadratic. Once you have the collision point, collision normal, and the velocities of the collision point relative to the two objects, you can solve the system by adding an impulse to one object and subtracting the same impulse from the other object so that the final relative velocity is such that the objects end up moving away from each other. In the 2D case this ends up a system of 7 linear equations, in 3D case it''s more like 15.

Anyway, just wanted to warn you about the complexity of this. I''ve actually been working on a 2D rbd engine for a few months, maybe close to 6. Here''s my demo using this engine..

http://www.geocities.com/bpj1138/rbd2d.zip

--bart

--bart
The spring method looks good to use for now, but eventually I''ll convert this to cars, sort of like a simple (very simple) version of GTA. How do I calculate the impluse, or change in momentum, or whatever you want to call it.

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If only I could write them down...
well, if you''re using the penalty method, impulse = area of intersection, or the larger the area of intersection the greater the impulse.

in the analytical method, impulse depends on all the variables, object masses, inertia, velocities, and the collision normal velocity.

i should add one more thing about the penalty method. one of the problems (well known in fact), is that if the velocities are too large, the objects will pass through each other. you''ll have to use some sort of timestepping approach.

l8r on..

--bart

--bart

This topic is closed to new replies.

Advertisement