From 1c79cff86e5cfae48e00184842101a9678b89903 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 5 Jan 2021 10:59:51 +0100 Subject: Lots of work, refactoring. --- complex_normal.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 complex_normal.hpp (limited to 'complex_normal.hpp') diff --git a/complex_normal.hpp b/complex_normal.hpp new file mode 100644 index 0000000..0819758 --- /dev/null +++ b/complex_normal.hpp @@ -0,0 +1,26 @@ +#pragma once +#include +#include + +template class complex_normal_distribution { +private: + std::normal_distribution d; + double δx; + double δy; + std::complex μ; + std::complex eθ; + +public: + complex_normal_distribution(std::complex μ, T σ, std::complex κ) : μ(μ), d(0, σ / sqrt(2)) { + δx = sqrt(1 + std::abs(κ)); + δy = sqrt(1 - std::abs(κ)); + eθ = std::polar(1.0, std::arg(κ)); + } + + template std::complex operator()(Generator& g) { + // First generate an axis-aligned complex number centered at the origin. + std::complex z(d(g) * δx, d(g) * δy); + // Shift and rotate the number. + return μ + eθ * z; + } +}; -- cgit v1.2.3-54-g00ecf