Class TetrahedronSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.shape.TetrahedronSampler
-
- All Implemented Interfaces:
ObjectSampler<double[]>
,SharedStateObjectSampler<double[]>
,SharedStateSampler<SharedStateObjectSampler<double[]>>
public class TetrahedronSampler extends java.lang.Object implements SharedStateObjectSampler<double[]>
Generate points uniformly distributed within a tetrahedron.-
Uses the algorithm described in:
Rocchini, C. and Cignoni, P. (2001)
Generating Random Points in a Tetrahedron.
Journal of Graphics Tools 5(4), pp. 9-12.
Sampling uses:
- Since:
- 1.4
- See Also:
- Rocchini, C. & Cignoni, P. (2001) Journal of Graphics Tools 5, pp. 9-12
-
-
Field Summary
Fields Modifier and Type Field Description private double[]
a
The first vertex.private double[]
b
The second vertex.private double[]
c
The third vertex.private double[]
d
The fourth vertex.private UniformRandomProvider
rng
The source of randomness.private static int
THREE_D
The dimension for 3D sampling.private static java.lang.String
VERTEX_A
The name of vertex a.private static java.lang.String
VERTEX_B
The name of vertex b.private static java.lang.String
VERTEX_C
The name of vertex c.private static java.lang.String
VERTEX_D
The name of vertex d.
-
Constructor Summary
Constructors Constructor Description TetrahedronSampler(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d)
TetrahedronSampler(UniformRandomProvider rng, TetrahedronSampler source)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private double[]
createSample(double p1msmtmu, double s, double t, double u)
Creates the sample given the random variatess
,t
andu
in the interval[0, 1]
ands + t + u <= 1
.static TetrahedronSampler
of(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d)
Create a tetrahedron sampler with verticesa
,b
,c
andd
.double[]
sample()
Create an object sample.TetrahedronSampler
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
-
-
-
-
Field Detail
-
THREE_D
private static final int THREE_D
The dimension for 3D sampling.- See Also:
- Constant Field Values
-
VERTEX_A
private static final java.lang.String VERTEX_A
The name of vertex a.- See Also:
- Constant Field Values
-
VERTEX_B
private static final java.lang.String VERTEX_B
The name of vertex b.- See Also:
- Constant Field Values
-
VERTEX_C
private static final java.lang.String VERTEX_C
The name of vertex c.- See Also:
- Constant Field Values
-
VERTEX_D
private static final java.lang.String VERTEX_D
The name of vertex d.- See Also:
- Constant Field Values
-
a
private final double[] a
The first vertex.
-
b
private final double[] b
The second vertex.
-
c
private final double[] c
The third vertex.
-
d
private final double[] d
The fourth vertex.
-
rng
private final UniformRandomProvider rng
The source of randomness.
-
-
Constructor Detail
-
TetrahedronSampler
TetrahedronSampler(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d)
- Parameters:
rng
- Source of randomness.a
- The first vertex.b
- The second vertex.c
- The third vertex.d
- The fourth vertex.
-
TetrahedronSampler
TetrahedronSampler(UniformRandomProvider rng, TetrahedronSampler source)
- Parameters:
rng
- Generator of uniformly distributed random numberssource
- Source to copy.
-
-
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 point within the tetrahedron.
-
createSample
private double[] createSample(double p1msmtmu, double s, double t, double u)
Creates the sample given the random variatess
,t
andu
in the interval[0, 1]
ands + t + u <= 1
. The sum1 - s - t - u
is provided. The sample can be obtained from the tetrahedronabcd
using:p = (1 - s - t - u)a + sb + tc + ud
- Parameters:
p1msmtmu
- plus 1 minus s minus t minus u (1 - s - t - u
)s
- the first variate st
- the second variate tu
- the third variate u- Returns:
- the sample
-
withUniformRandomProvider
public TetrahedronSampler 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 TetrahedronSampler of(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d)
Create a tetrahedron sampler with verticesa
,b
,c
andd
. Sampled points are uniformly distributed within the tetrahedron.No test for a volume is performed. If the vertices are coplanar the sampling distribution is undefined.
- Parameters:
rng
- Source of randomness.a
- The first vertex.b
- The second vertex.c
- The third vertex.d
- The fourth vertex.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException
- If the vertices do not have length 3; or vertices have non-finite coordinates
-
-