public abstract class TriangleSampler extends Object implements SharedStateObjectSampler<double[]>
Turk, G. Generating random points in triangles. Glassner, A. S. (ed) (1990).
Graphic Gems Academic Press, pp. 24-28.
Sampling uses:
| Modifier and Type | Method and Description |
|---|---|
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. |
static TriangleSampler |
of(UniformRandomProvider rng,
double[] a,
double[] b,
double[] c)
Create a triangle sampler with vertices
a, b and c. |
double[] |
sample()
Create an object sample.
|
abstract TriangleSampler |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsamples, samplespublic double[] sample()
ObjectSamplersample in interface ObjectSampler<double[]>protected abstract double[] createSample(double p1msmt, double s, double t)
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
p1msmt - plus 1 minus s minus t (1 - s - t)s - the first variate st - the second variate tpublic abstract TriangleSampler withUniformRandomProvider(UniformRandomProvider rng)
withUniformRandomProvider in interface SharedStateSampler<SharedStateObjectSampler<double[]>>rng - Generator of uniformly distributed random numbers.public static TriangleSampler of(UniformRandomProvider rng, double[] a, double[] b, double[] c)
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.
rng - Source of randomness.a - The first vertex.b - The second vertex.c - The third vertex.IllegalArgumentException - If the vertices do not have the same
dimension; the dimension is less than 2; or vertices have non-finite coordinatesCopyright © 2016–2022 The Apache Software Foundation. All rights reserved.