Closed GoogleCodeExporter closed 9 years ago
Looking at your set of values this is most likely a result of lack of floating
point precision.
This is because of your data range. If you translate and scale your point
values to be in the range -1 and 1 you should be fine I think.
Just translating to be in centered around 0 should be enough but the epsilon
used in the lib is tuned for values in the range 0 and 1. So scaling helps with
precision tests to.
Original comment by thahlen@gmail.com
on 6 Mar 2014 at 6:03
So if you have your points in an array[] you should try this:
Sometime you might also have to round values to 12 decimals since poly2tri uses
en epsilon of 1.0e-12 for some tests.
double d;
double[] range = new double[] { Double.MAX_VALUE,
Double.MIN_VALUE,Double.MAX_VALUE, Double.MIN_VALUE };
double[] center = new double[2];
for( int i=0; i<array.length; i += 2 )
{
range[0] = Math.min( array[i], range[0] );
range[1] = Math.max( array[i], range[1] );
range[2] = Math.min( array[i+1], range[2] );
range[3] = Math.max( array[i+1], range[3] );
}
center[0] = (range[0] + range[1])/2;
center[1] = (range[2] + range[3])/2;
if( (range[1]-range[0]) > (range[3]-range[2]) )
{
d = 2/(range[1] - range[0]);
}
else
{
d = 2/(range[3] - range[2]);
}
for( int i=0; i<array.length; i += 2 )
{
array[i] = d*(array[i] - center[0]);
array[i+1] = d*(array[i+1] - center[1]);
}
Original comment by thahlen@gmail.com
on 6 Mar 2014 at 6:24
This was a precision issue in input data
Original comment by thahlen@gmail.com
on 2 Apr 2014 at 9:47
Original issue reported on code.google.com by
imp...@gmail.com
on 6 Mar 2014 at 4:34