Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-131

TriangleSampler: Sample uniformly within a triangle

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.4
    • 1.4
    • sampling
    • None

    Description

      Create a sampler to sample uniformly within a triangle:

      public abstract class TriangleSampler implements 
              SharedStateSampler<TriangleSampler> {
          public static TriangleSampler of(double[] a,
                                           double[] b,
                                           double[] c,
                                           UniformRandomProvider rng);
      }
      

      Sampling of a point p can be performed within a triangle with vertices a, b, c using:

      v = b - a
      w = c - a
      
      p = a + s * v + t * w
      
      with s and t uniform deviates in [0, 1] and s + t <= 1
      
      Note: When s + t > 1 then transform s = 1 - s and t = 1 - t.

      This algorithm is described in:
      Turk, G. Generating random points in triangles. Glassner, A. S. (ed) (1990).
      Graphic Gems, Academic Press, pp. 24-28.

      The method is applicable to any number of dimensions for the vertices. The triangle defines the 2D Euclidean space (plane) for sampling.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 20m
                  1h 20m