Java Random Int randomPointsFromUnitSphere(int n)

Here you can find the source of randomPointsFromUnitSphere(int n)

Description

random Points From Unit Sphere

License

Open Source License

Declaration

public static double[][] randomPointsFromUnitSphere(int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double[][] randomPointsFromUnitSphere(int n) {
        if (n <= 0) {
            throw new IllegalArgumentException();
        }/*from   ww  w .j av  a 2 s.  c  o m*/

        double[][] result = new double[n][3];

        for (int i = 0; i < n; i++) {

            //Spherical Coordinates!
            double phi = Math.PI * Math.random();
            double theta = 2 * Math.PI * Math.random();

            double x = Math.cos(theta) * Math.sin(phi);
            double y = Math.sin(theta) * Math.sin(phi);
            double z = Math.cos(phi);

            result[i][0] = x;
            result[i][1] = y;
            result[i][2] = z;
        }

        return result;

    }
}

Related

  1. randomNumberWithinRange(int low, int high)
  2. randomNumberWithinRange(int min, int max)
  3. randomPass(int n)
  4. randomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t)
  5. randomPointsFromFigureEight(int n)
  6. randomPointsFromUnitSquare(int n)
  7. randomQuickSort(int[] array)
  8. randomRange(int min, int max)
  9. randomSize(int maxValue)