public static double deltaAngle(double angle1, double angle2) {
		while (angle2 <= -180)
			angle2 += 360;
		while (angle2 > 180)
			angle2 -= 360;
		while (angle1 <= -180)
			angle1 += 360;
		while (angle1 > 180)
			angle1 -= 360;
		
		double r = angle2 - angle1;
		return r + ((r > 180) ? -360 : (r < -180) ? 360 : 0);
	}