Class TriangleSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.shape.TriangleSampler
-
- All Implemented Interfaces:
ObjectSampler<double[]>
,SharedStateObjectSampler<double[]>
,SharedStateSampler<SharedStateObjectSampler<double[]>>
public abstract class TriangleSampler extends Object implements SharedStateObjectSampler<double[]>
Generate points uniformly distributed within a triangle.-
Uses the algorithm described in:
Turk, G. Generating random points in triangles. Glassner, A. S. (ed) (1990).
Graphic Gems Academic Press, pp. 24-28.
Sampling uses:
- Since:
- 1.4
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract double[]
createSample(double p1msmt, double s, double t)
Creates the sample given the random variatess
andt
in the interval[0, 1]
ands + t <= 1
.static TriangleSampler
of(UniformRandomProvider rng, double[] a, double[] b, double[] c)
Create a triangle sampler with verticesa
,b
andc
.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.rng.sampling.ObjectSampler
samples, samples
-
-
-
-
Method Detail
-
sample
public double[] sample()
Description copied from interface:ObjectSampler
Create an object sample.- Specified by:
sample
in interfaceObjectSampler<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 variatess
andt
in the interval[0, 1]
ands + t <= 1
. The sum1 - 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 st
- the second variate t- Returns:
- the sample
-
withUniformRandomProvider
public 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.- Specified by:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateObjectSampler<double[]>>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
public static TriangleSampler of(UniformRandomProvider rng, double[] a, double[] b, double[] c)
Create a triangle sampler with verticesa
,b
andc
. 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
-
-