Sign in to follow this  
jakesee

Car knocking over a barrel

Recommended Posts

Hello... For past 4 weeks, I have been trying to work out how to solve the physics for knocking over/toppling/tilting/flip/rotate/roll an object like a barrel after hitting by another object say, a car... but without success. Anyone wants to drop hints for me? One idea I have is to use 2 spheres, one on top of the other and then hit the lower sphere with a sloping plane. This would give the lower sphere a force in the plane normal direction causing it to "fly". For the upper sphere, I want to connect it to the lower using "rigid rod". But the problem is I canot find a way to code the "rigid rod". I did a spring using f = kx which worked fine, but a rigid rod is surprisingly hard for me... Maybe my idea is just bad, so... any help would be greatly appreciated =) Thanks!

Share this post


Link to post
Share on other sites
Well, if you really want to do it that way, you have the velocity-verlet solution for adding rigidity to point-mass systems.

http://www.teknikus.dk/tj/gdc2001.htm

Share this post


Link to post
Share on other sites
This is definitely a difficult problem. You are trying to simulate rigid body collision dynamics. Assuming you can find the positions and velocities on impact, you need to know the inertia tensor and the mass for each object to calculate the forces. If you can figure out how all that works, then you should be able to calculate what happens each frame.

However, teh internets is particularly dry on the subject of the Inertia tensor. I've asked my profs at engineering school about it, the best answer I got was "Thats graduate school work". I've been looking at this problem as well, which is why I know that there are no good tutorials.

The next best solution to using the actual inertia tensor method is to use a few point masses to approximate the mass distribution, and then link the forces in some way. If you use a rigid model for your forcing calculations, that would be equivalent to the inertia tensor method except less computationally efficient (but easier). If you know any calculus, the inertia tensor method is what you get when you take the limit of this method as the number of point masses approaches Inifinity, which allows some optimizations to the math. I believe that 4 point masses placed appropriately is enough to give you the exact result. 6 point masses with variable mass but fixed position relative to your body should also work. I'm not sure how you would calculate the collision forces with this(point masses) model.

A further approximation is to use point masses and some kind of springs and a fancy integrator to deal with force propogation.

The basic idea is to avoid thinking about the inertia tensor by composing your mass distribution out of simple mass distributions that are easy to deal with. Spheres for example are a nice easy one, because the inertia tensor is just one number for them as opposed to 6 for an arbitrary mass distribution.

Of course if you can figure out the inertia tensor, that would be the fastest and most elegant solution.

Share this post


Link to post
Share on other sites
You dont have to simulate the connection between the two spheres. They can be considered the same object, an object composed of two spheres. When either sphere moves the other moves directly with it. There is then only one set of state variables for the object. Which makes the computation fairly simple.

The body can be easily integrated with euler integration. It's the interaction part that complicates things. It would be fairly easy to get a single object colliding and interacting correctly. But when you start to have multiple simultaneous collision, such as stacking, things get a lot more complicated.

Share this post


Link to post
Share on other sites
@apefish
Indeed, there is virtually nothing substantial on the inertia tensor stuff. The best i can find is the source code for Box2D, which unfortunately is in 2D!

@bzroom
I don't think that's what I want because using the same force/velocity vector on both the masses will not cause it to rotate as desired? Not sure if i uderstood correctly...

@oliii
Thanks for the link. I have been away reading the article and coding away. Turns out th rigid body automatically handles torques which is excellent! However, it appears the the "rigid rod" constraint or constant separation constrian is interering advesely with the collision logic.

Wonder if anyone can point out my mistake in the implementation?

I have a rigid box with 8 point mass on each vertex of the box. When any one of the mass penetrates the ground plane due to constant gravity, I simply shift it up to the point of impact.

This shifting will voilate the equi-distance constraint and during the satisfy constrain phase, the mass will be pushed through the ground plane again. This causes a system that never stabalises.

In theory, I could put a flag to indicate "if touch ground, do not satisfy constraint". But is this the way to do it? How else should I do it.

Furthermore, the constant gravity continues to act on the point mass creating a larger and larger velocity. Should I apply an equal and opposite force (upward gravity) on the point mass or should I just set he Y-axis velocity to zero?

Share this post


Link to post
Share on other sites
For your box penetration thing. I take it you are just taking a direct move-it approach to meeting constraints. That's fine but you have to be smart about how you implement it with constraints that may conflict (This causes your problem).

To fix your current system, I think extra flags or information at each point about what degrees of freedom you have might help. I don't know if this would work or not though. This might get into heavy matrix solving (O(n^3), yuk), and I can think of situations where the constraints can't be satisfied that would cause trouble.

The other way to deal with this kind of thing is with penalty functions, basically everything is a spring. so when you detect that it is below ground, simply apply a force that might restore it, and when your internal shape constraints are violated, just apply forces. everything just sortof works itself out with this, but you have to tune your spring constants well. The trouble with this is that it is slow to respond and it can oscillate and stuff.

I really don't know much about constraint solving, so that's all I can say. I suggest you look into how they do it in box2d or ODE or something. That might help. There might not be any general method for constraint solving, it might just come down to special case detection. Like if you have an object on the ground that gets a force, you can have some special logic that says "meet any force without yielding". Good luck!

Share this post


Link to post
Share on other sites
Quote:
For past 4 weeks, I have been trying to work out how to solve the physics for knocking over/toppling/tilting/flip/rotate/roll an object like a barrel after hitting by another object say, a car... but without success.

Anyone wants to drop hints for me?

I've only thought about this in the past and I don't know how close it comes to realism or how fast it is but it should be close enough and look about right.

Assuming your have the point of impact and the force applied, calculate the torque with T=Fxr, T being the toque, F the force applied and r the vector from the object's centre of mass to the point of impact. The x operation is the cross product.

Now use the moment of inertia to calculate the angular acceleration, T=I*a. You can find some simple formulas for I of some basic shapes on the net, for more complex ones just build the object out of basic objects and sum up all the inertias. You can pre calculate the inertia. Now having your angular acceleration vector you can calculate the angular velocity of your objects should it be rotating about it's centre of mass.

Rotate your objects in small steps on the rotation axis you found earlier(normalized torque), once rotated by a small amount, get the difference in vertex position and use a ray intersect along those difference vectors with collide-able objects to determine if they hit, if they do get the vertex with the shortest hit distance and use that as your rotation point, if they don't take another step until you make a full rotation.

Once you got your rotation point you can apply your angular velocity to it. That should take care of the rotational part of the physics involved.

Once again I don't know how fast this is or how close to reality it is

[Edit] Just realized that inertia changes with axis of rotation, there is a formula for correcting this, however I need to look it up in my physics book which I don't have with me atm

Share this post


Link to post
Share on other sites
Quote:
Original post by jakesee
@bzroom
I don't think that's what I want because using the same force/velocity vector on both the masses will not cause it to rotate as desired? Not sure if i uderstood correctly...


I haven't read through the new parts of the thread so i dont know where the discussion has gone. But in response to your comment. There would be only a single mass. One rigid body. it just has two spheres to make its shape up.

Imagine a dumbbell. It's two spheres for collision but it's only a single mass, single rigid object.

Share this post


Link to post
Share on other sites
Particle systems have lots of drawbacks imo. Friction, solving penetration, modelling inertia accurately, fixed timestep... They are better at modelling soft bodies, cloth or ropes.

On the other hand, rigid body dynamics is hardly a walk in the park either.

here is an example of a 3D box on a plane.

It's not hugely complicated to model (no friction), but the step up is actually very hard. Integration stability issues, fixing jitter, static friction, stacking... Those are problems that are not so easy to solve.

If you'd want to model a barrel using rigid body dynamics, you'll also have to consider the problem of collision. Barrels are cylinders, and their collision detection is quite tricky. However, approximating then to a collection of spheres can work for you, But you could always reduce them to a polytope (approximate caps using a circle approximation, say 8 or 10 facets, extrude, and use the Separating Axis Theorem for collision detection).

All in all, if you really want workable physics, best is to use an engine. They even do complicated stuff like constraints for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this