VecmathUtil { static Vector2d average(final Collection<Vector2d> vectors) { final Vector2d average = new Vector2d(0, 0); for (final Vector2d vector : vectors) { average.add(vector); } average.scale(1d / vectors.size()); return average; } private  VecmathUtil();   }
@Test public void testAverage() throws Exception { Vector2d mean = VecmathUtil.average(Arrays.asList(new Vector2d(0.5, 0.5), new Vector2d(0.5, -0.5))); assertThat(mean.x, closeTo(0.5d, 0.01)); assertThat(mean.y, closeTo(0d, 0.01)); }