Commit 6575d8c6 authored by Quentin Khan's avatar Quentin Khan

Make plummer distribution stay in given radius

parent 218e681c
...@@ -243,6 +243,7 @@ FReal plummerDist(FSize& cpt, const FReal &R) { ...@@ -243,6 +243,7 @@ FReal plummerDist(FSize& cpt, const FReal &R) {
} }
} }
/** /**
* \brief Build N points following the Plummer distribution * \brief Build N points following the Plummer distribution
* *
...@@ -258,11 +259,16 @@ FReal plummerDist(FSize& cpt, const FReal &R) { ...@@ -258,11 +259,16 @@ FReal plummerDist(FSize& cpt, const FReal &R) {
*/ */
template <class FReal> template <class FReal>
void unifRandomPlummer(const FSize N, const FReal R, FReal * points) { void unifRandomPlummer(const FSize N, const FReal R, FReal * points) {
constexpr const FReal rand_max = 0.995;
constexpr const FReal r_max = std::sqrt(1.0/(std::pow(rand_max, -2.0/3.0) - 1.0));
std::cerr << r_max << '\n';
unifRandomPointsOnSphere<FReal>(N, 1, points); unifRandomPointsOnSphere<FReal>(N, 1, points);
FReal mc = 1.0/static_cast<FReal>(N); FReal mc = 1.0/static_cast<FReal>(N);
for (FSize i = 0, j = 0 ; i< N ; ++i, j+=4) { for (FSize i = 0, j = 0 ; i< N ; ++i, j+=4) {
FReal m = getRandom<FReal>(); FReal m = getRandom<FReal>();
FReal r = FMath::Sqrt( 1.0/(FMath::pow(m, -2.0/3.0) - 1.0)) ; m = m > rand_max ? rand_max : m;
FReal r = FMath::Sqrt(1.0/(FMath::pow(m, -2.0/3.0) - 1.0)) / r_max;
points[j] *= r; points[j] *= r;
points[j+1] *= r; points[j+1] *= r;
points[j+2] *= r; points[j+2] *= r;
......
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