public static double getDifferenceFromDirection(double b1, double b2) {
        double r = (b2 - b1) % 360.0;
        if (r < -180.0) {
            r += 360.0;
        }
        if (r >= 180.0) {
            r -= 360.0;
        }
        return Math.abs(r);
    }
Calculate the angle defined by 3 points
(and deliver it's cosine on the fly)
main/src/main/java/cgeo/geocaching/brouter/util/CheapAngleMeter.java