Code Monkey home page Code Monkey logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
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 [email protected] on 6 Mar 2014 at 6:03

from poly2tri.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
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 [email protected] on 6 Mar 2014 at 6:24

from poly2tri.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 22, 2024
This was a precision issue in input data

Original comment by [email protected] on 2 Apr 2014 at 9:47

  • Changed state: WontFix

from poly2tri.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.