Commit 85dd5159 authored by andy's avatar andy
Browse files

ENH: triangle - added cachedRandom random point function

parent ecd53eae
...@@ -40,6 +40,7 @@ SourceFiles ...@@ -40,6 +40,7 @@ SourceFiles
#include "tensor.H" #include "tensor.H"
#include "pointHit.H" #include "pointHit.H"
#include "Random.H" #include "Random.H"
#include "cachedRandom.H"
#include "FixedList.H" #include "FixedList.H"
#include "UList.H" #include "UList.H"
#include "linePointRef.H" #include "linePointRef.H"
...@@ -162,6 +163,10 @@ public: ...@@ -162,6 +163,10 @@ public:
// distribution // distribution
inline Point randomPoint(Random& rndGen) const; 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 //- Calculate the barycentric coordinates of the given
// point, in the same order as a, b, c. Returns the // point, in the same order as a, b, c. Returns the
// determinant of the solution. // determinant of the solution.
......
...@@ -244,6 +244,25 @@ inline Point Foam::triangle<Point, PointRef>::randomPoint(Random& rndGen) const ...@@ -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> template<class Point, class PointRef>
Foam::scalar Foam::triangle<Point, PointRef>::barycentric Foam::scalar Foam::triangle<Point, PointRef>::barycentric
( (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment