1.2.4. Random

1.2.4.1. Random samplers

raysect.core.math.random.seed()

Seeds the random number generator with the specified integer.

If a seed is not specified the generator is automatically re-seed using the system cryptographic random number generator (urandom).

Parameters:d – Integer seed.
raysect.core.math.random.uniform()

Generate random doubles in range [0, 1).

Values are uniformly distributed.

Returns:Random double.
raysect.core.math.random.normal()

Generates a normally distributed random number.

The mean and standard deviation of the distribution must be specified.

Parameters:
  • mean (float) – The distribution mean.
  • stddev (float) – The distribution standard deviation.
Returns:

Random double.

raysect.core.math.random.probability()

Samples from the Bernoulli distribution where P(True) = prob.

For example, if probability is 0.8, this function will return True 80% of the time and False 20% of the time.

Values of prob outside the [0, 1] range of probabilities will be clamped to the nearest end of the range [0, 1].

Parameters:prob (double) – A probability from [0, 1].
Returns:True or False.
Return type:bool

1.2.4.2. 3D Surface Samplers

class raysect.core.math.sampler.surface3d.SurfaceSampler3D

Base class for an object that generates samples from a surface in 3D.

__call__

If samples is not provided, returns a single Point3D sample from the distribution. If samples is set to a value then a number of samples equal to the value specified is returned in a list.

If pdf is set to True the Point3D sample is returned inside a tuple with its associated pdf value as the second element.

Parameters:
  • samples (int) – Number of points to generate (default=None).
  • pdf (bool) – Toggle for returning associated sample pdfs (default=False).
Returns:

A Point3D, tuple or list.

class raysect.core.math.sampler.surface3d.DiskSampler3D

Bases: raysect.core.math.sampler.surface3d.SurfaceSampler3D

Generates Point3D samples from a disk centred in the x-y plane.

Parameters:radius (double) – The radius of the disk in metres (default=1).
class raysect.core.math.sampler.surface3d.RectangleSampler3D

Bases: raysect.core.math.sampler.surface3d.SurfaceSampler3D

Generates Point3D samples from a rectangle centred in the x-y plane.

Parameters:
  • width (double) – The width of the rectangle.
  • height (double) – The height of the rectangle.
class raysect.core.math.sampler.surface3d.TriangleSampler3D

Bases: raysect.core.math.sampler.surface3d.SurfaceSampler3D

Generates Point3D samples from a triangle in 3D space.

Parameters:
  • v1 (Point3D) – Triangle vertex 1.
  • v2 (Point3D) – Triangle vertex 2.
  • v3 (Point3D) – Triangle vertex 3.

1.2.4.3. Solid Angle Samplers

class raysect.core.math.sampler.solidangle.SolidAngleSampler

Base class for an object that generates samples over a solid angle.

__call__

If samples is not provided, returns a single Vector3D sample from the distribution. If samples is set to a value then a number of samples equal to the value specified is returned in a list.

If pdf is set to True the Vector3D sample is returned inside a tuple with its associated pdf value as the second element.

Parameters:
  • samples (int) – Number of points to generate (default=None).
  • pdf (bool) – Toggle for returning associated sample pdfs (default=False).
Returns:

A Vector3D, tuple or list of Vector3D objects.

pdf()

Generates a pdf for a given sample value.

Vectors must be normalised.

Parameters:sample (Vector3D) – The sample point at which to get the pdf.
Return type:float
class raysect.core.math.sampler.solidangle.SphereSampler

Bases: raysect.core.math.sampler.solidangle.SolidAngleSampler

Generates a random vector on a unit sphere.

class raysect.core.math.sampler.solidangle.HemisphereUniformSampler

Bases: raysect.core.math.sampler.solidangle.SolidAngleSampler

Generates a random vector on a unit hemisphere.

The hemisphere is aligned along the z-axis - the plane that forms the hemisphere base lies in the x-y plane.

class raysect.core.math.sampler.solidangle.HemisphereCosineSampler

Bases: raysect.core.math.sampler.solidangle.SolidAngleSampler

Generates a cosine-weighted random vector on a unit hemisphere.

The hemisphere is aligned along the z-axis - the plane that forms the hemisphere base lies in the x-y plane.

class raysect.core.math.sampler.solidangle.ConeUniformSampler

Bases: raysect.core.math.sampler.solidangle.SolidAngleSampler

Generates a uniform weighted random vector from a cone.

The cone is aligned along the z-axis.

Parameters:angle – Angle of the cone in degrees (default=45).