REGION_SAMPLE is a FORTRAN90 library which samples various computational regions.
A computational region is a (usually finite) subset of 2D, 3D or M-dimensional space, which is often an ideal model of some physically interesting space, such as a channel in which liquid is flowing, or the body of some metallic structure. For certain algorithms, it is necessary to "sample" this region, that is, to select, uniformly at random, a set of N points that lie in the region.
It's easy to do this for the unit square or hypercube, simply by invoking the pseudorandom number generator. It's also easy to extend this idea to any rectangular object. However, this gets more difficult to do when the region has a curved or complicated geometry, which might include holes.
One way to handle many different kinds of regions in a uniform way is to allow the sampling of the region to be carried out by a subroutine which "knows" the region's shape. The input to the subroutine is simply N, the number of points requested, and the routine generates the points using whatever method is appropriate. When all else fails, a rejection method can usually be used.
REGION_SAMPLE is simply a collection of some of the routines that have been used for such computations.
The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.
DISCRETE_PDF_SAMPLE a MATLAB program which demonstrates how to construct a Probability Density Function (PDF) from a table of sample data, and then to use that PDF to create new samples.
PLOT_POINTS is a FORTRAN90 program which can be used to create Encapsulated PostScript images (EPS files) from the output files.
RANDOM_DATA is a FORTRAN90 program which produces random data from a number of regions.
RBOX is a C program which produces random data from a number of regions.
REGION_SAMPLE is available in a C++ version and a FORTRAN90 version and a MATLAB version.
RSITES is a C++ program which produces random data in an M-dimensional box.
TABLE is a format which is used to store the input and output files used by the program.
UNIFORM is a FORTRAN90 library which samples the uniform random distribution.
Test files you may copy include:
FORK is a subset of [0,100] x [0,100] comprising a rectangular "handle" and semicircular annulus that resembles an inverted tuning fork:
SPHERE is the interior of a sphere:
You can go up one level to the FORTRAN90 source codes.