summaryrefslogtreecommitdiff
path: root/complex_normal.hpp
blob: 8ed75d1b735bdc5548d9f5bc539b47640d42686a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

#include <complex>
#include <random>

template <class T = double> class complex_normal_distribution {
private:
  std::normal_distribution<T> d;
  double δx;
  double δy;
  std::complex<T> μ;
  std::complex<T>;

public:
  complex_normal_distribution(std::complex<T> μ, T σ, std::complex<T> κ) : μ(μ), d(0, σ / sqrt(2)) {
    δx = sqrt(1 + std::abs(κ));
    δy = sqrt(1 - std::abs(κ));= std::polar(1.0, std::arg(κ));
  }

  template <class Generator> std::complex<T> operator()(Generator& g) {
    // First generate an axis-aligned complex number centered at the origin.
    std::complex<T> z(d(g) * δx, d(g) * δy);
    // Shift and rotate the number.
    return μ +* z;
  }
};