Problem with 3d impulse and collisions
Ok so I'm writing a 3D game that uses impulse to determine how things behave when they collide. In this game I have two cubes. Now the shape of each cube is defined by 9 spheres, sort of like this:
http://mark.reid.name/images/figures/highdim3d.png Though in my game the middle sphere is larger. I am using the equations found here: http://www.euclideanspace.com/physic...reed/index.htm So far everything works as it should except for one small detail. If I line the cubes up and place them as close as possible to each other, sort of like this: http://staticp3.fotolia.com/jpg/00/...BQHhRWxkQm.jpg (and btw these aren't from my game their just random pictures from the internet I thought might be helpful). Anyways if I position the cubes as shown in that picture I am able to rotate them through each other, which is obviously not what would happen in real life. Basically If the cubes have only linear velocity or have linear velocity and angular velocity everything works. But if the cubes only have angular velocity and are next to each other like in the picture they will rotate through each other. Keep in mind this isn't due to the fact that the collision of the cubes is represented with spheres. I am able to see the spheres that compose the cubes and can clearly see them going through each other (I also tried this with rectangles where it became very obvious something was wrong). I would think in this type of situation that one of two things should happen: 1) In the case they are perfectly lined up and the angular velocity is small then nothing should happen . 2) In the case that they are not perfectly lined up but are still close or when the angular velocity of one of them is really large they should turn each other like gears. I have checked my code again and again and have found nothing wrong. I believe that the equation I found at the euclidean space site does not account for this type of motion. So does anyone know how to account for this type of motion and how I could incorporate it into my current equation? 
Re: Problem with 3d impulse and collisions
That's because formulae you are using are only good for collisions. You don't want to be using these when you slowly push the two cubes into each other.
There is a reason why people usually don't do collisions like that. Compute forces. Do simulation that way. 
Re: Problem with 3d impulse and collisions
So what should I be doing then? I don't know what you mean by computing the forces.

Re: Problem with 3d impulse and collisions
For every step of the simulation, do the following:
1) Check for collisions. 2) For every collision pair, check how much the two objects overlap. Use Hook's law (or any monotonous law, really) compute repulsion force. 3) Combine forces from collision and any other forces you wish to add into net force and net torque. 4) Compute linear and angular accelerations. 5) Use finite time increment to compute [itex]\Delta v = a * \Delta t[/itex] 6) Do the same to find change in position, angular velocity, and orientation matrix/quatternion. 7) Rinse, repeat. This is how most modern game engines work, including Havok. The main differences from one engine to another are how they detect collisions, determine the forces from these, and how the velocity and position changes are interpolated. (You will notice that without any interpolation, this recipe results in poor energyconservation in collisions. If you run into this problem, I can give you a few tips on resolving them.) 
Re: Problem with 3d impulse and collisions
I'm just not getting it. I've looked online and downloaded a few books about game physics. It just seems like no one knows how to do this. Most of the information and all the examples are obfuscated horribly and there aren't any simple clear concise tutorials anywhere.

Re: Problem with 3d impulse and collisions
Heh. Yes. Because people who write books on game designs are programmerwriters. Finding someone who's a programmerphysicistwriter is near damn impossible. So your best bet is to try and ask someone who is a physicist, comfortable with programming, and have done that before and stepped on most of the rakes associated with the problem.
That's why I'm trying to help. :) Not that I've written anything supercomplex, but definitely on the scope you're working with. Plus, I've worked with physics engines written by other people enough to know a little about how these work as well. 
Re: Problem with 3d impulse and collisions
Ok so assuming there aren't any other forces aside from the two objects colliding how should I be calculating net force and torque. Is the net force just the result I get from using hooke's law?
As for torque. Wiki says its r x F. The F just stands for force but I'm confused about r which is a "displacement vector". Would I just use the point of collision for this value? Also for the displacement in hooke's law should I be using the volume of overlap between the spheres that represent the area of my rigid body or some kind of 1 dimensional linear value? 
Re: Problem with 3d impulse and collisions
Quote:
Quote:
Quote:
Part of the reason why linear distance works well is because you know that for the time of collision, it's going to essentially work as an oscillator. That might help you with debugging. One thing you can do to save yourself trouble. Instead of computing force from just current positions, take average of this frame and previous frame. The reason for that is if you integrate Hook's Law in discrete steps, you consistently overintegrate. If you average it like above, the average error is zero. Also, make sure that your Hook's constant is appropriate for the time step you are using. If you make it too stiff, the collision will happen in too few steps, and you'll have large error. If it's too soft, the objects will visibly overlap. 
Re: Problem with 3d impulse and collisions
Wait you saying overlap depth =  R1  R1;
I'm assuming R1 and R2 are the respective radii of each sphere? Shouldn't the location of the spheres be incorporated into that? What I tried doing was finding the vector from the center of one sphere to the other, then multiplying it by each of their respective radii (keeping in mind that the radii would not necessarily be the same for each sphere) and find the distance between these two points. But that wouldn't work in the case the sphere's were perfectly overlapped since I'd have to normalize the distance vector (which would cause division by zero). So is there a way to calculate overlap depth between two spheres without dividing by distance? 
Re: Problem with 3d impulse and collisions
I guess that sentence is a bit ambiguous. Depth = (distance  R1  R2). And yes, these are radii.
If the two centers meet, you have other problems, such as, which way is the force pointing. You should set your Hook's constant to be high enough to avoid this scenario. 
Re: Problem with 3d impulse and collisions
Okay then but how do I convert that 1D value into a vector for force? I tried taking the distance of each component, ie
x_force = abs(x1  x2)  radius1  radius2; y_force = abs(y1  y2)  radius1  radius2; z_force = abs(z1  z2)  radius1  radius2; where abs returns the absolute value But that didn't work out too well. Would I have to calculate the normal of the collision and then multiply this by the magnitude of the force? If so how should I be calculating the normal? 
Re: Problem with 3d impulse and collisions
I think this is going to be easier.
Code:
//Returns force experienced by sphere 1 at x1 due to sphere 2 at x2. 
Re: Problem with 3d impulse and collisions
For the most part everything is working but there's a couple of problems:
1) The cubes are still rotating through each other (which was my problem with the other method). 2) I've been arbitrarily assigning k. Right now the cubes collide properly unless I accelerate one of them really fast. Is there some proper way to calculate k based on velocity/acceleration? I'm thinking with the rotation it might be due to a lack of friction (isn't that what causes gearlike rotation in the first place?). Just to clarify I'm calculating the change in angular velocity to be the torque multiplied by the inverse inertia_tensor. I'm pretty certain I'm calculating the tensor correctly. 
Re: Problem with 3d impulse and collisions
1) Do you treat the entire cube as a rigid body? Id est, do you compute the inertia tensor for the entire cube out of sphere contributions? Or how do you handle torque on cubes?
2) The value of k should depend on the time step, and that also limits velocities the simulation can handle. A really advanced engine may scale the time step depending on complexity of the situation, but that can cause lags. 
Re: Problem with 3d impulse and collisions
Okay so I am calculating the inertia tensor based on the entire cube (ie the eight points that make it up). I calculate the overlap and point of intersection based on the individual spheres but I calculate the force and torque based on the average overlap and the 'average' point of intersection. So lets say that the two faces of the cube are lined up and intersect. There would be five points of interaction between ten spheres but the average point of intersection would be the middle of the cube.
So in short Inertia is based on the entire cube and torque is based on the average point of intersection and the total force. The total force being calculated based on the average overlap. 
Re: Problem with 3d impulse and collisions
Don't average them. Just make each spheresphere collision generate its own force. Add forces from all spheres that belong to a cube to get total force, and add all torques from each rxF to get total torque.
I think, that might be the problem. If the two spheres on opposite sides touch, if you just average point of force application, there is no net torque when cubes try to rotate through each other. If you compute torques first, then add them, the side that overlaps more will be the one providing dominant torque, and that should help. 
Re: Problem with 3d impulse and collisions
Alright well I did that and didn't see any change in behavior. The linear part works and the angular part works if there is some linear velocity but if there is only angular velocity the cubes can still be rotated through each other.
Here's my actual code if you want to take a look, it's in GML so it might be a little strange. It's basically like c++ though. Code:
//the with statement makes the first cube cycle through all the instances of the other cube (there's only 1 so it doesn't really matter) Also you might notice there's no time step calculation. Basically when you see something like a += d it means that d will be added to the current value of a every time step (which is 1/120th of a second at the moment). Though don't get confused, when I do this in the for loop it is only added to the current value once. For instance when you see x_FORCE += xf; it means that xf is added to the current value of x_FORCE once per iteration of the for loop. 
Re: Problem with 3d impulse and collisions
I don't know if this is a cause of your problem or not, but I haven't found any other issues yet.
Forces are equalandopposite on the two boxes. So you can compute force on both in one go. But that's not true for torques. The torques are only equalandopposite around common origin. But torque around center of mass of one cube will not be equal to minus the torque around the center of the other, because you just changed the origin around which torque is measured. It's a relative quantity. Anyways, a better way to handle this, and it might be a good idea in case you decide to have more objects later, is to make this call for each cube, and compute forces and torques for current cube only. Alternatively, you can try to figure out the torque on the second cube within your code, but you'll need to create x/y/z_torque2 from rax/y/z crossed with x/y/z_FORCE, where rax/y/z are redefined relative to other.x/y/z. I can only venture a guess that at your chosen location, the torque around first cube's center is zero, but not around second cube's, and that might be the reason they rotate through each other. But it might be something else. I'll take another look through the code to see if I find anything else. 
All times are GMT 5. The time now is 06:57 PM. 
Powered by vBulletin Copyright ©2000  2014, Jelsoft Enterprises Ltd.
© 2014 Physics Forums