Class TriangleSampler

    • Method Detail

      • sample

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

        protected abstract double[] createSample​(double p1msmt,
                                                 double s,
                                                 double t)
        Creates the sample given the random variates s and t in the interval [0, 1] and s + t <= 1. The sum 1 - s - t is provided. The sample can be obtained from the triangle abc using:
         p = a(1 - s - t) + sb + tc
         
        Parameters:
        p1msmt - plus 1 minus s minus t (1 - s - t)
        s - the first variate s
        t - the second variate t
        Returns:
        the sample
      • of

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

        Sampling is supported in dimensions of 2 or above. Samples will lie in the plane (2D Euclidean space) defined by using the three triangle vertices to create two vectors starting at a point in the plane and orientated in different directions along the plane.

        No test for collinear points is performed. If the points are collinear the sampling distribution is undefined.

        Parameters:
        rng - Source of randomness.
        a - The first vertex.
        b - The second vertex.
        c - The third vertex.
        Returns:
        the sampler
        Throws:
        IllegalArgumentException - If the vertices do not have the same dimension; the dimension is less than 2; or vertices have non-finite coordinates