Class TetrahedronSampler
java.lang.Object
org.apache.commons.rng.sampling.shape.TetrahedronSampler
- All Implemented Interfaces:
ObjectSampler<double[]>
,SharedStateObjectSampler<double[]>
,SharedStateSampler<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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final double[]
The first vertex.private final double[]
The second vertex.private final double[]
The third vertex.private final double[]
The fourth vertex.private final UniformRandomProvider
The source of randomness.private static final int
The dimension for 3D sampling.private static final String
The name of vertex a.private static final String
The name of vertex b.private static final String
The name of vertex c.private static final String
The name of vertex d. -
Constructor Summary
ConstructorsConstructorDescriptionTetrahedronSampler
(UniformRandomProvider rng, double[] a, double[] b, double[] c, double[] d) TetrahedronSampler
(UniformRandomProvider rng, TetrahedronSampler source) -
Method Summary
Modifier and TypeMethodDescriptionprivate 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.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 Details
-
THREE_D
private static final int THREE_DThe dimension for 3D sampling.- See Also:
-
VERTEX_A
The name of vertex a.- See Also:
-
VERTEX_B
The name of vertex b.- See Also:
-
VERTEX_C
The name of vertex c.- See Also:
-
VERTEX_D
The name of vertex d.- See Also:
-
a
private final double[] aThe first vertex. -
b
private final double[] bThe second vertex. -
c
private final double[] cThe third vertex. -
d
private final double[] dThe fourth vertex. -
rng
The source of randomness.
-
-
Constructor Details
-
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 Details
-
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
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:
IllegalArgumentException
- If the vertices do not have length 3; or vertices have non-finite coordinates
-