This is very interesting. With this amount of geometry code, I could picture 
this as part of a commons-geometry-rng module. The SurfaceSampler, for example, 
could make use of the TriangleMesh and Triangle3D classes. This would also be 
an opportunity to expand support for N-dimensional points and vectors.

-Matt
________________________________
From: Alex Herbert <[email protected]>
Sent: Saturday, April 24, 2021 9:48 AM
To: Commons Developers List <[email protected]>
Subject: Re: [RNG][Geometry] TriangleSampler and other shape samplers

On Fri, 23 Apr 2021 at 23:31, Gilles Sadowski <[email protected]> wrote:

> Le ven. 23 avr. 2021 à 23:42, Alex Herbert <[email protected]> a
> écrit :
>
> > Should new coordinate based samplers be moved to a package inside for
> > example:
> >
> > o.a.c.rng.sampling.geometry
> > o.a.c.rng.sampling.shape
>
> Maybe.  I guess that "UnitSphereSampler" would be moved too (and thus
> deprecated in the package where it currently resides).
>
> Do you foresee many "shapes"?
> And a way to "combine" them?
>

I required a unit disc for use in testing a convex hull algorithm. This
created the UnitBallSampler. When looking at options I found the Wolfram
page 'Random Point Picking' has a lot of sampling examples and expected
results of sampling [1]. I thought that primitive shapes would be useful
for someone. So at least:

- TriangleSampler (ND)
- LineSampler (ND)
- TetrahedronSampler (3D only)

There is also a UnitSimplexSampler which samples from the surface of an ND
simplex: x1 + x2 + ... + xn = 1; 0 <= xi <= 1. This can be done by sampling
from an exponential distribution and normalising so would be possible with
the current library. I thought about a UnitCubeSampler which although
trivial may be useful.

For sampling a surface the TriangleSampler can be combined with the
AliasMethodSamplerDiscreteSampler. The surface should be triangulated. The
area of each triangle is used to create a distribution of which triangle to
pick using the alias method. A sample is then taken from the chosen
triangle. This would require a robust method to compute the area of a
triangle even when containing very acute or obtuse angles. Input could be
vertices and face indices:

public static SurfaceSampler of(double[] vertices, int[][] faces,
UniformRandomProvider);

The AliasMethodSamplerDiscreteSampler handles up to 2^31-1 discrete items
so should work even with very large surfaces (with a lot of memory).

A similar approach can be done with a volume using the TetrahedronSampler
but would be restricted to 3D. Thus far I have not found a method to sample
from an ND volume other than the UnitBall or UnitCube.

The UnitSphereSampler can be deprecated and a new version created to use a
factory method to create the sampler (allowing optimisation for low
dimensions). This would have:

o.a.c.rng.sampling.shape

UnitSphereSampler (N-surface)
UnitBallSampler (N-volume)
UnitSimplexSampler (N-surface)
LineSegmentSampler (N-dimension points on a line segment between 2 points)
TriangleSampler (N-dimension points within a triangle in a 2D plane)
TetrahedronSampler (3D points inside a tetrahedron)
SurfaceSampler (ND points on a triangulated surface)
VolumeSampler (3D points inside a volume composed of tetrahedrons)

? UnitCubeSampler (N-volume)

On Sat, 24 Apr 2021 at 12:27, Matt Juntunen <[email protected]>
wrote:

> One more question: what are the originating use cases for these shape
> samplers?
>

I use them for testing programs that deal with 2/3D points that are part of
a shape. For example I've a program that performs 3 channel unmixing on
photoactivated flourophores. To test this it is useful to draw random
structures of points in each channel that are different such as lines,
circles and triangles. If the unmixing works then the same shaped
structures are all the same colour when viewed as an RBG image. Another
example is drawing 2D/3D points for testing convex and concave hull
algorithms. It is easy to draw some primitive shapes and test if the hull
produces an area/volume as expected.

[1] https://mathworld.wolfram.com/topics/RandomPointPicking.html

Reply via email to