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
- is a child of
-
RNG-132 Package rng.sampling.shape for sampling coordinates from shapes
- Closed