NetDEM v1.0
Loading...
Searching...
No Matches
golden_spiral_sampler.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "mini_map.hpp"
5#include "utils_math.hpp"
6
7namespace netdem {
8
18public:
23
28
39 static GoldenSpiralSampler instance;
40 return instance;
41 }
42
52 VecXT<Vec3d> Get(int num_samples) {
53 VecXT<Vec3d> samples(num_samples);
54
55 for (int i = 0; i < num_samples; i++) {
56 double theta = std::acos(1.0 - 2.0 * (i + epsilon) /
57 (num_samples - 1.0 + 2.0 * epsilon));
58 double phi = two_pi_by_lambda * i;
59 Vec3d vert_sph = {1.0, theta, phi};
60 samples[i] = Math::SphericalToCartesian(vert_sph);
61 }
62
63 return samples;
64 }
65
66private:
67 const double lambda = (1.0 + std::sqrt(5.0)) / 2.0;
68 const double two_pi_by_lambda = 2.0 * Math::PI / lambda;
69 const double epsilon = 0.36;
70
72};
73
74} // namespace netdem
A class for generating samples from a weighted spherical centroidal Voronoi tessellation.
Definition golden_spiral_sampler.hpp:17
VecXT< Vec3d > Get(int num_samples)
Generate a specified number of sample points.
Definition golden_spiral_sampler.hpp:52
GoldenSpiralSampler & operator=(const GoldenSpiralSampler &)=delete
Delete copy assignment operator.
GoldenSpiralSampler(const GoldenSpiralSampler &)=delete
Delete copy constructor.
static GoldenSpiralSampler & GetInstance()
Get a reference to the singleton GoldenSpiralSampler instance.
Definition golden_spiral_sampler.hpp:38
static constexpr double PI
Definition utils_math.hpp:15
static Vec3d SphericalToCartesian(Vec3d const &vert_sph)
Definition utils_math.cpp:206
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31
std::array< double, 3 > Vec3d
Definition utils_macros.hpp:18