mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: triangle - added cachedRandom random point function
This commit is contained in:
@ -40,6 +40,7 @@ SourceFiles
|
||||
#include "tensor.H"
|
||||
#include "pointHit.H"
|
||||
#include "Random.H"
|
||||
#include "cachedRandom.H"
|
||||
#include "FixedList.H"
|
||||
#include "UList.H"
|
||||
#include "linePointRef.H"
|
||||
@ -162,6 +163,10 @@ public:
|
||||
// distribution
|
||||
inline Point randomPoint(Random& rndGen) const;
|
||||
|
||||
//- Return a random point on the triangle from a uniform
|
||||
// distribution
|
||||
inline Point randomPoint(cachedRandom& rndGen) const;
|
||||
|
||||
//- Calculate the barycentric coordinates of the given
|
||||
// point, in the same order as a, b, c. Returns the
|
||||
// determinant of the solution.
|
||||
|
||||
@ -244,6 +244,25 @@ inline Point Foam::triangle<Point, PointRef>::randomPoint(Random& rndGen) const
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
inline Point Foam::triangle<Point, PointRef>::randomPoint
|
||||
(
|
||||
cachedRandom& rndGen
|
||||
) const
|
||||
{
|
||||
// Generating Random Points in Triangles
|
||||
// by Greg Turk
|
||||
// from "Graphics Gems", Academic Press, 1990
|
||||
// http://tog.acm.org/GraphicsGems/gems/TriPoints.c
|
||||
|
||||
scalar s = rndGen.sample01<scalar>();
|
||||
|
||||
scalar t = sqrt(rndGen.sample01<scalar>());
|
||||
|
||||
return (1 - t)*a_ + (1 - s)*t*b_ + s*t*c_;
|
||||
}
|
||||
|
||||
|
||||
template<class Point, class PointRef>
|
||||
Foam::scalar Foam::triangle<Point, PointRef>::barycentric
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user