Class TetrahedronSampler

java.lang.Object
org.apache.commons.rng.sampling.shape.TetrahedronSampler
All Implemented Interfaces:
ObjectSampler<double[]>, SharedStateObjectSampler<double[]>, SharedStateSampler<SharedStateObjectSampler<double[]>>

public class TetrahedronSampler extends Object implements SharedStateObjectSampler<double[]>
Generate points uniformly distributed within a tetrahedron.
  • Uses the algorithm described in:
    Rocchini, C. and Cignoni, P. (2001)
    Generating Random Points in a Tetrahedron.
    Journal of Graphics Tools 5(4), pp. 9-12.

Sampling uses:

Since:
1.4
See Also:
  • Field Details

    • THREE_D

      private static final int THREE_D
      The dimension for 3D sampling.
      See Also:
    • VERTEX_A

      private static final String VERTEX_A
      The name of vertex a.
      See Also:
    • VERTEX_B

      private static final String VERTEX_B
      The name of vertex b.
      See Also:
    • VERTEX_C

      private static final String VERTEX_C
      The name of vertex c.
      See Also:
    • VERTEX_D

      private static final String VERTEX_D
      The name of vertex d.
      See Also:
    • a

      private final double[] a
      The first vertex.
    • b

      private final double[] b
      The second vertex.
    • c

      private final double[] c
      The third vertex.
    • d

      private final double[] d
      The fourth vertex.
    • rng

      private final UniformRandomProvider rng
      The source of randomness.
  • Constructor Details

    • TetrahedronSampler

      TetrahedronSampler(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d)
      Parameters:
      rng - Source of randomness.
      a - The first vertex.
      b - The second vertex.
      c - The third vertex.
      d - The fourth vertex.
    • TetrahedronSampler

      TetrahedronSampler(UniformRandomProvider rng, TetrahedronSampler source)
      Parameters:
      rng - Generator of uniformly distributed random numbers
      source - Source to copy.
  • Method Details

    • sample

      public double[] sample()
      Description copied from interface: ObjectSampler
      Create an object sample.
      Specified by:
      sample in interface ObjectSampler<double[]>
      Returns:
      a random Cartesian point within the tetrahedron.
    • createSample

      private double[] createSample(double p1msmtmu, double s, double t, double u)
      Creates the sample given the random variates s, t and u in the interval [0, 1] and s + t + u <= 1. The sum 1 - s - t - u is provided. The sample can be obtained from the tetrahedron abcd using:
       p = (1 - s - t - u)a + sb + tc + ud
       
      Parameters:
      p1msmtmu - plus 1 minus s minus t minus u (1 - s - t - u)
      s - the first variate s
      t - the second variate t
      u - the third variate u
      Returns:
      the sample
    • withUniformRandomProvider

      public TetrahedronSampler withUniformRandomProvider(UniformRandomProvider rng)
      Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.
      Specified by:
      withUniformRandomProvider in interface SharedStateSampler<SharedStateObjectSampler<double[]>>
      Parameters:
      rng - Generator of uniformly distributed random numbers.
      Returns:
      the sampler
    • of

      public static TetrahedronSampler of(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d)
      Create a tetrahedron sampler with vertices a, b, c and d. Sampled points are uniformly distributed within the tetrahedron.

      No test for a volume is performed. If the vertices are coplanar the sampling distribution is undefined.

      Parameters:
      rng - Source of randomness.
      a - The first vertex.
      b - The second vertex.
      c - The third vertex.
      d - The fourth vertex.
      Returns:
      the sampler
      Throws:
      IllegalArgumentException - If the vertices do not have length 3; or vertices have non-finite coordinates