#! /usr/bin/env python # def circle01_sample ( n, seed ): #*****************************************************************************80 # ## CIRCLE01_SAMPLE samples points on the circumference of the unit circle in 2D. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 June 2015 # # Author: # # John Burkardt # # Reference: # # Russell Cheng, # Random Variate Generation, # in Handbook of Simulation, # edited by Jerry Banks, # Wiley, 1998, pages 168. # # Reuven Rubinstein, # Monte Carlo Optimization, Simulation, and Sensitivity # of Queueing Networks, # Krieger, 1992, # ISBN: 0894647644, # LC: QA298.R79. # # Parameters: # # Input, integer N, the number of points. # # Input/output, integer SEED, a seed for the random # number generator. # # Output, real X(2,N), the points. # import numpy as np from r8vec_uniform_01 import r8vec_uniform_01 r = 1.0 c = np.zeros ( 2 ) theta, seed = r8vec_uniform_01 ( n, seed ) x = np.zeros ( [ 2, n ] ) for j in range ( 0, n ): x[0,j] = c[0] + r * np.cos ( 2.0 * np.pi * theta[j] ) x[1,j] = c[1] + r * np.sin ( 2.0 * np.pi * theta[j] ) return x, seed def circle01_sample_test ( ): #*****************************************************************************80 # ## CIRCLE01_SAMPLE_TEST tests CIRCLE01_SAMPLE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 June 2015 # # Author: # # John Burkardt # import platform from r8mat_transpose_print import r8mat_transpose_print print ( '' ) print ( 'CIRCLE01_SAMPLE_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' CIRCLE01_SAMPLE samples the unit circle.' ) n = 10 seed = 123456789 x, seed = circle01_sample ( n, seed ) r8mat_transpose_print ( 2, n, x, ' Sample points in the unit circle.' ) # # Terminate. # print ( '' ) print ( 'CIRCLE01_SAMPLE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) circle01_sample_test ( ) timestamp ( )