Vectors { public static double[][] regularVectors(final int nVectors) { final double[][] vectors = new double[nVectors][]; final double inc = Math.PI * (3 - Math.sqrt(5)); final double off = 2 / (double) nVectors; for (int k = 0; k < nVectors; k++) { final double y = k * off - 1 + (off / 2); final double r = Math.sqrt(1 - y * y); final double phi = k * inc; final double x = Math.cos(phi) * r; final double z = Math.sin(phi) * r; final double[] vector = { x, y, z }; vectors[k] = vector; } return vectors; } private  Vectors(); static double[] randomVector(); static double[][] randomVectors(final int nVectors); static double[][] regularVectors(final int nVectors);  }
@Test public void testRegularVectors() { final int n = 1000; final double[][] v = Vectors.regularVectors(n); for (int i = 0; i < n; i++) { final double x = v[i][0]; final double y = v[i][1]; final double z = v[i][2]; final double length = Math.sqrt(x * x + y * y + z * z); assertEquals(1, length, 1e-9); } }