载入中...
搜索中...
未找到
OceanFourierInternal.h
浏览该文件的文档.
1#pragma once
2
3#include <complex>
4#include <numbers>
5#include <vector>
6
8using Complex = std::complex<double>;
9inline constexpr double tau = 2.0 * std::numbers::pi;
10// Unnormalized inverse transform: coefficients represent physical amplitudes,
11// so no N-dependent scale enters either wave height or the authoring parameters.
15inline void inverse1D(std::vector<Complex>& a) {
16 const auto n = a.size();
17 for (std::size_t i = 1, j = 0; i < n; ++i) {
18 auto bit = n >> 1;
19 for (; j & bit; bit >>= 1) j ^= bit;
20 j ^= bit;
21 if (i < j) std::swap(a[i], a[j]);
22 }
23 for (std::size_t length = 2; length <= n; length <<= 1) {
24 const auto step = std::polar(1.0, tau / static_cast<double>(length));
25 for (std::size_t start = 0; start < n; start += length) {
26 Complex w{1.0, 0.0};
27 for (std::size_t j = 0; j < length / 2; ++j) {
28 const auto even = a[start + j], odd = a[start + j + length / 2] * w;
29 a[start + j] = even + odd;
30 a[start + j + length / 2] = even - odd;
31 w *= step;
32 }
33 }
34 }
35}
39inline void inverse2D(std::vector<Complex>& a, unsigned n) {
40 std::vector<Complex> line(n);
41 for (unsigned z = 0; z < n; ++z) {
42 for (unsigned x = 0; x < n; ++x) line[x] = a[z * n + x];
44 for (unsigned x = 0; x < n; ++x) a[z * n + x] = line[x];
45 }
46 for (unsigned x = 0; x < n; ++x) {
47 for (unsigned z = 0; z < n; ++z) line[z] = a[z * n + x];
49 for (unsigned z = 0; z < n; ++z) a[z * n + x] = line[z];
50 }
51}
52
53// Normalized forward transform paired with the physical-amplitude inverse.
57inline void forward2D(std::vector<Complex>& a, unsigned n) {
58 for (auto& value : a) value = std::conj(value);
59 inverse2D(a, n);
60 const double scale = 1.0 / double(n * n);
61 for (auto& value : a) value = std::conj(value) * scale;
62}
63} // namespace eve::fluids::ocean_detail
double z
double x
Duration start
float w
Definition AnimClip.cpp:738
glm::vec3 n
Definition Grass.cpp:63
float length
std::array< float, 3 > scale
MeleePoint3 a
Definition MeleeHit.cpp:40
Object::Ptr value
unsigned line
float step
Definition TreeMesh.cpp:451
void inverse1D(std::vector< Complex > &a)
Transform a validated power-of-two line in place without normalization. @cost O(N log N) arithmetic,...
std::complex< double > Complex
void forward2D(std::vector< Complex > &a, unsigned n)
Produce normalized Fourier amplitudes from a validated N by N spatial grid. @cost O(N squared log N) ...
void inverse2D(std::vector< Complex > &a, unsigned n)
Transform a validated N by N grid in place using row/column scratch. @cost O(N squared log N) arithme...