@ Nonnull public static Point fromUniformlyDistributedRandomPoints ( @ Nonnull final Random randomGenerator ) { checkNonnull ( "randomGenerator" , randomGenerator ) ; // Calculate uniformly distributed 3D point on sphere (radius = 1.0): // http://mathproofs.blogspot.co.il/2005/04/uniform-random-distribution-on-sphere.html final double unitRand1 = randomGenerator . nextDouble ( ) ; final double unitRand2 = randomGenerator . nextDouble ( ) ; final double theta0 = ( 2.0 * Math . PI ) * unitRand1 ; final double theta1 = Math . acos ( 1.0 - ( 2.0 * unitRand2 ) ) ; final double x = Math . sin ( theta0 ) * Math . sin ( theta1 ) ; final double y = Math . cos ( theta0 ) * Math . sin ( theta1 ) ; final double z = Math . cos ( theta1 ) ; // Convert Carthesian 3D point into lat/lon (radius = 1.0): // http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates final double latRad = Math . asin ( z ) ; final double lonRad = Math . atan2 ( y , x ) ; // Convert radians to degrees. assert ! Double . isNaN ( latRad ) ; assert ! Double . isNaN ( lonRad ) ; final double lat = latRad * ( 180.0 / Math . PI ) ; final double lon = lonRad * ( 180.0 / Math . PI ) ; return fromDeg ( lat , lon ) ; }
Create a random point uniformly distributed over the surface of the Earth .