From 6575d8c63f3afb9a23827364c26b6c2a94061637 Mon Sep 17 00:00:00 2001 From: Quentin Khan Date: Fri, 22 Jul 2016 16:15:50 +0200 Subject: [PATCH] Make plummer distribution stay in given radius --- Src/Files/FGenerateDistribution.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Src/Files/FGenerateDistribution.hpp b/Src/Files/FGenerateDistribution.hpp index 7d31f63c..1a547e39 100644 --- a/Src/Files/FGenerateDistribution.hpp +++ b/Src/Files/FGenerateDistribution.hpp @@ -243,6 +243,7 @@ FReal plummerDist(FSize& cpt, const FReal &R) { } } + /** * \brief Build N points following the Plummer distribution * @@ -258,11 +259,16 @@ FReal plummerDist(FSize& cpt, const FReal &R) { */ template 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(N, 1, points); FReal mc = 1.0/static_cast(N); for (FSize i = 0, j = 0 ; i< N ; ++i, j+=4) { FReal m = getRandom(); - 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+1] *= r; points[j+2] *= r; -- GitLab