You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2021/04/23 21:24:00 UTC
[jira] [Created] (RNG-131) TriangleSampler: Sample uniformly within
a triangle
Alex Herbert created RNG-131:
--------------------------------
Summary: TriangleSampler: Sample uniformly within a triangle
Key: RNG-131
URL: https://issues.apache.org/jira/browse/RNG-131
Project: Commons RNG
Issue Type: New Feature
Components: sampling
Affects Versions: 1.4
Reporter: Alex Herbert
Create a sampler to sample uniformly within a triangle:
{code:java}
public abstract class TriangleSampler implements
SharedStateSampler<TriangleSampler> {
public static TriangleSampler of(double[] a,
double[] b,
double[] c,
UniformRandomProvider rng);
}
{code}
Sampling of a point p can be performed within a triangle with vertices a, b, c using:
{noformat}
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.{noformat}
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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)