Fast Distance Calculations
marcus • June 17th, 2007
Fiddled a bit with distance calculation methods using various ‘fast square root’ algorithms vs. javas’ Math.sqrt today. So far, this one is about 2-5x faster than the default processing dist(...) method. (tested on osx only; power pc + intel)
public static final float fastDist (int x1, int y1, int x2, int y2)
{
return (float) Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}Here’s the code for all tests: DistancePerformanceTests.pde