Astronomical { static double interpolateAngles(double y2, double y1, double y3, double n) { final double a = DoubleUtil.unwindAngle(y2 - y1); final double b = DoubleUtil.unwindAngle(y3 - y2); final double c = b - a; return y2 + ((n/2) * (a + b + (n * c))); }    }
@Test public void testAngleInterpolation() { final double i1 = Astronomical.interpolateAngles( 1, -1, 3, 0.6); assertThat(i1).isWithin(0.000001).of(2.2); final double i2 = Astronomical.interpolateAngles( 1, 359, 3, 0.6); assertThat(i2).isWithin(0.000001).of(2.2); }