diff --git a/cosets/CMakeLists.txt b/cosets/CMakeLists.txt index c8cf75b..61e4c6b 100644 --- a/cosets/CMakeLists.txt +++ b/cosets/CMakeLists.txt @@ -17,3 +17,6 @@ add_custom_command( ) add_executable(coxeter src/tc.cpp) + +add_executable(mirror src/mirror.cpp) +target_link_libraries(mirror PRIVATE glm) diff --git a/cosets/src/mirror.cpp b/cosets/src/mirror.cpp new file mode 100644 index 0000000..4fe887e --- /dev/null +++ b/cosets/src/mirror.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +template +using vecn = glm::vec; + +float dot(int n, glm::vec4 a, glm::vec4 b) { + float sum = 0; + for (int i = 0; i < n; ++i) { + sum += a[i] * b[i]; + } + return sum; +} + +template +std::vector mirror(const float (&arr)[N - 1][N - 1]) { + static_assert(1 <= N and N <= 4, "Vector size is unsupported"); + + std::vector mirrors{}; + for (int p = 0; p < N; ++p) { + glm::vec4 vp{}; + for (int m = 0; m < p; ++m) { + glm::vec4 vq = mirrors[m]; + float a = cos(M_PI / arr[p-1][m]); + float b = dot(m, vp, vq); + float c = vq[m]; + float d = a - b / c; + vp[m] = d; + } + vp[p] = std::sqrt(1 - glm::dot(vp, vp)); + + for (const auto &v : mirrors) { + if (glm::dot(vp, v) > 0) { + vp *= -1; + break; + } + } + + mirrors[p] = vp; + } + + return mirrors; +} + +int main(int argc, char *argv[]) { + int planes = 3; + auto normals = mirror<3>((float[2][2]) { + {4}, + {2, 3} + }); + + for (const auto &normal : normals) { + std::cout << glm::to_string(normal) << std::endl; + } + + return 0; +} \ No newline at end of file