Dynamic shape but same surface size

Hi guys, I'm sorry if I won't be clear but I'm not really into physics and so I don't know the technical terms. My problem is that I would like a 2d "blob" which I can modifying its shape applying different forces but where the surface will be always the same size.
I reckon I would need a physic library like box2d, but, in this case, what's next?

Thanks a lot, chr
Box2D is really designed for rigid bodies, not blob shaped things. But, so are most engines, so I wouldn't give up too easily. Blobs are usually implemented in box2d and other engines as a bunch over overlapping circles held near each other by springs. But that doesn't fufill your constraint. I'm not sure how to do that really, the true physics behind that sort of thing is quite messy, so people usually fudge it.

BTW in 2D you need to change your terminology somewhat; by "surface" do you mean the area or the perimeter. Fixed perimeter is doable as a "jointed rope", like tank treads, while fixed area is the difficult one.
Hi Boris, unfortunately I mean the area 🙁

I'm wondering if I need image processing algorithms instead.


Thanks, chr
This is not using Box2d, but I did a quick blob demo at one point: http://www.ewjordan.com/processing/VolumeBlob/

Source is linked - it's a .pde file, which means it's technically written in Processing, but it's almost exactly Java code. Should be fairly simple to understand. To integrate with Box2d might be a bit more work, but wouldn't be impossible. The main problem with a direct port is that the example uses Verlet integration and position correction (i.e. velocities are all implicit), so you'd need to solve the equations for the equivalent position/velocity corrections in a normal integration scheme and then create some sort of joint that applied them (we don't have any N-body joints yet, I'm not sure how well they would fit in). There also aren't particles in Box2d, though a small circle works in a pinch.
Ok, it turns out that N-body constant volume/perimeter joints aren't actually all that difficult to do, later tonight I'll post some code with a demo. 🙂
ewjordan, i'm curious as to what algorithms are behind that code. Perhaps it isn't terribly complicated to apply it to, say a ring of rectangles (in box2d).
Well, the particular method I'm using is extremely simple and naive, at least for particles. Start with a target volume (area in 2d) and a target perimeter (the two are hopefully consistent, i.e. the volume is low enough that an object with that perimeter can support it). Then for each step...

1) Apply distance constraints between each pair of neighbor particles to (iteratively) satisfy the perimeter constraint.
2) Calculate the area of the blob using cross products
3) Compare the area to the target area
4) Push each edge out (or pull it in) along its normal by an amount that will add the appropriate amount of area to the blob
5) Rinse and repeat

This works easily when using Verlet integration because the velocity changes are implicit in the position correction, so that's all we need. Right now I'm working on separating the position correction and velocity corrections so that this fits well with Box2d's other contacts and joints (position based constraints don't lend themselves too well to warm starting when you "translate" them). One nice thing is that instead of manually performing step 1) we can merely create sub-joints which are usual distance or revolute joints, depending on the type of blob you're creating (particle or rectangle based).

I was going to write up how to solve the velocity errors, but let me hold off on that and try it first, then when I'm sure I'm right I'll tell you how I did it. 🙂 I'm going to try and get this somewhat in line with the way the other joints are solved, which should work a lot better. Then maybe I'll be able to more easily add support for rings of rectangles rather than just circles.
I'm kind of interested in this because it would be good for making tires or other such "squishy" objects. Perhaps modify some parameters and it would be a good starting point for dynamic shape deformation without breakage for things like metal/plastic, where if a sharp corner hits something it would get "flattened" and "dents" become natural.
This sounds like a good approach, but there is a bit of danger it will look very unrealistic in some circumstances, as you are not modelling the internal of the blob as having any dynamics.
For example, suppose I have a "dumbell" shaped blob, i.e. two blobs connected by a very thin bridge. You would expect a sudden blow to one blob to have a negligable effect on the other, but in your circumstances:
a) As the first blob is compressed a bit, you'd see both blobs being expanded afterwards, i.e. some of the area has travelled a very long distance from one blob to another instantaneously.
b) The a significant number of the blob's particles form the bridge, not the circles, which is different from the correct distribution of mass where the bridge is virtually weightless. Unless you weight the particles in some way, or have particles inside the blob as well, you will end up with very odd mass behaviour.
BorisTheBrave wrote:
a) As the first blob is compressed a bit, you'd see both blobs being expanded afterwards, i.e. some of the area has travelled a very long distance from one blob to another instantaneously.
b) The a significant number of the blob's particles form the bridge, not the circles, which is different from the correct distribution of mass where the bridge is virtually weightless. Unless you weight the particles in some way, or have particles inside the blob as well, you will end up with very odd mass behaviour.

Right, so what we're modeling is really a massless incompressible gas contained in a flexible but unstretchable container (where "incompressible" and "unstretchable" are modified by the fact that we'll always have error in the solver). Actually, a dumbell would be impossible to make in this way, because you'd need external constraints holding the dumbell shape in place (everything ends up settling into a normal old blob shape if not otherwise constrained).

There are ways to handle structured soft bodies, maybe if I can get this working I'll take a look and see if that seems reasonable to attempt. From what I remember, the tradeoff is that as usual you need to model a lot more of the internals to get better behavior - you can allow for some deformation of a structured body by treating it as a single unit, but for the most realistic effects you really need to consider it as many independently deformable units joined together. Bullet now has a soft rabbit demo that looks pretty good in real time, so I'll check into how that's done, maybe we can try something similar.

Original thread: https://box2d.org/forum/viewtopic.php?t=1504