Deformable and breakable body - sample

Now the only thing holding me back is the actual constrained delaunay bit: If the delaunay triangulation does not contain all of the segments that make up the polygon, it craps out.

I guess I'll have to attempt a remedy for this by myself.

One possibly simple to implement method that I just thought of is:

(pseudocode)

Code: Select all

while (numTriangles == 0)
{
   find longest segment in polygon, split it in two (# polygon segments increases by 1)
   run triangulator
   set numTriangles to returned valid triangles   // if a segment is not in triangulation it gives zero for numTriangles
}


The problem with that is, if I made a polygon that had 10 really long edges, it may need to divide up all the long segments so this algorithm would run the triangulation algorithm up to 10 times. Good for me not having to do work and re-code some nasty complicated stuff, but not good for speed!

Maybe I could do some statistical analysis on the segment lengths, and repeatedly split segments until maximum length is within some range of the median/mean...

Other than doing that I'd need to resort to some kind of segment insertion algorithm (for a polygon edge not in triangulation, create edge by cutting up triangles in the way) on the complete delaunay triangulation which I don't have any idea how to do.

edit: Doesnt seem like shortening segments will even necessarily make it work. nooooo!
do you have an example ?
i do not really understand, what you want to do
For instance I want to create this shape:

Image

So this goes into the triangulator as a series of points. The segments are obviously made from point 1 to point 2, 2 to 3, etc. However this doesn't do constrained minimal delaunay triangulation, so it doesn't seem to be able to insert segments in a minimal triangulation, so when the delaunay triangulation is returned:

Image

then you will notice that one of the thick black lines was erased. This segment, which I need in my shape, is not a part of the triangulation itself, and so currently with Options (2|16), it will simply return zero triangles. If i change it to (16) without the 2, then it'll give me the entire triangulation.

You may think that this phenomenon is rare, and I thought so too (since I had a hard time coming up with trivial cases where this happened) but once I made a drawer method to let the user draw out a polygon, almost half the time it fails.

So I think what I'll do is just take some code that does a pure delaunay triangulation and work something out. ewjordan's little ConvexDecomposition add-on has lots of nice little helper functions and I think I can get it done with their help.
dc443 wrote:edit: Doesnt seem like shortening segments will even necessarily make it work. nooooo!

Are you sure about that? I'm pretty sure one of the properties of Delaunay triangulation is that the nearest neighbor point is always connected by an edge, which means that subdividing a desired edge enough should always do the trick...
ewjordan wrote:
dc443 wrote:edit: Doesnt seem like shortening segments will even necessarily make it work. nooooo!

Are you sure about that? I'm pretty sure one of the properties of Delaunay triangulation is that the nearest neighbor point is always connected by an edge, which means that subdividing a desired edge enough should always do the trick...


Right, but there's situations where for a certain shape there would need to be infinite divisions in order for the delaunay conditions to be satisfied. Like with the regular meshing settings for this thing (the subject of this thread), which does in fact create a sort of constrained delaunay, if you give it a shape with sharp edges (similar to the one i drew above), you can get it to have corners with a pattern of triangles getting smaller and smaller as it approaches the corner. I saw an explanation of this on one of the papers somewhere on the net. I can draw a diagram of this, if you don't get what I'm saying.

This is why I wanted a minimumAngle setting that I could set to a very small value (or, the value of the smallest angle found in the particular polygon) so that I can eliminate this.

At the moment the mesher is great at generating large amounts of triangles with a decent amount of flexibility but I want to squeeze the most speed out of box2d with custom defined convex polygons, which means as few sub-polygons in the decomposition as possible.
There is still a bug in small angles, when using tmO_BASICMESH, as mentioned.
If you have solution, i'd appreciate if you could share it.
nimodo wrote:There is still a bug in small angles, when using tmO_BASICMESH, as mentioned.
If you have solution, i'd appreciate if you could share it.


Well you could look for and identify a repeating pattern of the same angles over and over, or test for triangles that are too small, or look for corners that have low angles, and then just temporarily ignore the angle constraints for them. I tried to do this through the settings, but they didn't change much.

I wouldn't know how to do it and I haven't even attempted at wading into the internals of any delaunay triangulators.

Currently I'm just taking the outputs and doing what I can with them.
I updated breakablebody, see first post for download http://www.box2d.org/forum/viewtopic.php?f=3&t=836
'd': enter drawing mode
'm': finish drawing mode and mesh
's': toggle static / dynamic body creation
dont close polygons

you should
- download recent TriangleMesh
- virtualize MouseUp and MouseDown in Test.h (e.g. virtual void ...)
breakablebody.jpg
breakablebody.jpg (128.98 KiB) Viewed 2661 times


saludos - nimodo
The codes dang brilliant...I was fiddling around with the Delauncy Triangulation code, and found it would break down for complex shapes with mixes of co-linear triangles and found adding an extra check in the CircumCircle(..) function mostly fixed it:

/* Check for coincident points */
if(abs(y1 - y2) < EPSILON && abs(y2 - y3) < EPSILON)
return(false);

/* Add extra check for horizontal co-linear tris */
if(abs(x1 - x2) < EPSILON && abs(x2 - x3) < EPSILON)
return(false);

Thanx again.

Ben

=)
Do you mean,
aborting in DeleteBadTriangles() because of CircumCenter() {check of very small triangles} =false ?

Do you have some geometry, so i can reproduce this case ?

hasta la vista
nimodo

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