This sort of follows on from the fluid simulation thread, here: viewtopic.php?f=3&t=574
I didn't know whether to just carry on posting there or start a new thread, but I thought a new thread would be best since it's a more general problem...
To cut a long story short, the fluid simulation I'm working on does the actual fluid simulation part almost entirely seperately from Box2D - it's just quicker for performance and memory to handle fluid particles myself. However, they still need to interact with Box2D, and one of the problems I have is getting fluid particles to interact properly with static level geometry.
My fluid particles are circles, with a centre position and a radius. They're integrated using a Verlet (rather than Euler) system, so if they intersect with something, all I have to do is to find a suitable place to reposition the particle, and the integration pretty much handles the velocities for me. My collision system basically looks for shapes in the same part of the world as the particle (I have a grid system and use an AABB query for this), and for each shape tests to see if the particle circle is inside the shape. If it is, we calculate the nearest point on the outside of the shape to move the particle to, and move it there.
This works well when the particles are only colliding with one static b2Shape at a time (such as walls or the ground), but it struggles with corners where two (or more) b2Shapes line up against each other, or intersect. Pushing the particle to the nearest position out of one shape it's intersecting may put it straight inside another shape, so my particles have a tendency to "leak" through gaps:

What should I do about this? How does the Box2D engine internals deal with these situations? (I've tried finding the code that deals with this, but the inner workings of Box2D are pretty impenetrable to me). I've tried doing another AABB test when pushing a particle out of a body, to make sure it's not going to be put inside another body, but (a) that's a lot of expensive AABB tests, and (b) even if the code does discover that there's a problem, at that point there's no sensible way to work out where the particle *should* go. I can set it back to its position from the previous frame, but its hardly an ideal solution.
I didn't know whether to just carry on posting there or start a new thread, but I thought a new thread would be best since it's a more general problem...
To cut a long story short, the fluid simulation I'm working on does the actual fluid simulation part almost entirely seperately from Box2D - it's just quicker for performance and memory to handle fluid particles myself. However, they still need to interact with Box2D, and one of the problems I have is getting fluid particles to interact properly with static level geometry.
My fluid particles are circles, with a centre position and a radius. They're integrated using a Verlet (rather than Euler) system, so if they intersect with something, all I have to do is to find a suitable place to reposition the particle, and the integration pretty much handles the velocities for me. My collision system basically looks for shapes in the same part of the world as the particle (I have a grid system and use an AABB query for this), and for each shape tests to see if the particle circle is inside the shape. If it is, we calculate the nearest point on the outside of the shape to move the particle to, and move it there.
This works well when the particles are only colliding with one static b2Shape at a time (such as walls or the ground), but it struggles with corners where two (or more) b2Shapes line up against each other, or intersect. Pushing the particle to the nearest position out of one shape it's intersecting may put it straight inside another shape, so my particles have a tendency to "leak" through gaps:

What should I do about this? How does the Box2D engine internals deal with these situations? (I've tried finding the code that deals with this, but the inner workings of Box2D are pretty impenetrable to me). I've tried doing another AABB test when pushing a particle out of a body, to make sure it's not going to be put inside another body, but (a) that's a lot of expensive AABB tests, and (b) even if the code does discover that there's a problem, at that point there's no sensible way to work out where the particle *should* go. I can set it back to its position from the previous frame, but its hardly an ideal solution.