Page 1 of 1

Autogeometry and toConvexHull

Posted: Fri May 11, 2012 7:46 pm
by ChAdams
ChipmunkPolyline > toConvexHull sometimes produces polygons which trigger polyshape validation failure.

in cpPolyShape.c:

Code: Select all

if(cpvcross(cpvsub(b, a), cpvsub(c, b)) > 0.0f)
I would suggest changing it to something like

Code: Select all

if(cpvcross(cpvsub(b, a), cpvsub(c, b)) > 0.000001f)

Re: Autogeometry and toConvexHull

Posted: Sat May 12, 2012 12:20 pm
by slembcke
I had that come up a couple times too. It's fixed in the current Git versions because I just made it so that the convex hull algorithm is always run when creating poly shapes. I'm getting pretty close to releasing 6.1, so it should be pretty stable.

The issue in 6.0.3 is that slightly different measures are used in the convex hull algorithm and the validate function so there are floating point precision issues. The Git code also has a function that allows you to create convex hulls with a distance tolerance. Points on the hull that contribute to the shape by less than the tolerance are dropped, creating simpler polygons.

In case you had forgotten, there is information on the downloads page for accessing the Chipmunk Pro git repository:
http://chipmunk-physics.net/downloads.php

Re: Autogeometry and toConvexHull

Posted: Sat May 12, 2012 2:26 pm
by ChAdams
Thanks, I'll check out the github version - although last time I tried to checkout chipmunk pro from git it wasn't able to pull, probably need to be using a different github client.