correctly generate vertices in N dimensions

This commit is contained in:
2019-09-14 19:39:35 -04:00
parent a8be8fe262
commit 2e4e84ab80
6 changed files with 92 additions and 83 deletions

View File

@@ -32,12 +32,9 @@ public:
program = build_program("main", vs, fs); program = build_program("main", vs, fs);
verts_data = vertices<3>({}, Multiplicites<3>({ verts_data = vertices<3>(
{0, 1, 5}, schlafli<3>({5, 3}),
{1, 2, 3} {10, 1, 1});
}), {
10, 1, 1
});
glGenBuffers(1, &verts); glGenBuffers(1, &verts);
glBindBuffer(GL_ARRAY_BUFFER, verts); glBindBuffer(GL_ARRAY_BUFFER, verts);
@@ -81,9 +78,7 @@ public:
glBindVertexArray(tri); glBindVertexArray(tri);
glUniform4f(0, 1, 1, 1, 1); glUniform4f(0, 1, 1, 1, 1);
glDrawArrays(GL_POINTS, 0, verts_data.size() - 3); glDrawArrays(GL_POINTS, 0, verts_data.size());
glUniform4f(0, 1, 1, 1, .1);
glDrawArrays(GL_TRIANGLES, verts_data.size() - 3, 3);
swapbuffers(); swapbuffers();
} }

View File

@@ -1,16 +1,20 @@
#include "util/mesh.hpp" #include "util/mesh.hpp"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto vs = vertices<3>({}, Multiplicites<3>({ const auto &mults = schlafli<4>({4, 3, 3});
{0, 1, 4}, const std::vector<glm::vec4> &vs = vertices<4>(mults, {10, 1, 1, 1});
{1, 2, 3}
}), {
1.0f, 1.0f, 1.0f
});
for (const auto &v : vs) { for (const auto &v:vs) {
std::cout << glm::to_string(v) << std::endl; std::cout << glm::to_string(v) << std::endl;
} }
return 0; // Table *table = solve({}, mults);
// std::cout << table->size() << std::endl;
//
// for (const auto &rel : mults.relations()) {
// for (const auto &e : rel) {
// std::cout << e << " ";
// }
// std::cout << std::endl;
// }
} }

View File

@@ -1,7 +1,7 @@
#include "util/mirrors.hpp" #include "util/mirrors.hpp"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
auto normals = mirror<3>(Multiplicites<3>({ auto normals = mirror<3>(Multiplicities<3>({
{0, 1, 4}, {0, 1, 4},
{1, 2, 3} {1, 2, 3}
})); }));

View File

@@ -5,39 +5,60 @@
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <map>
struct Mult { #include <tuple>
int a, b, mult;
};
template<int N> template<int N>
struct Multiplicites { struct Mults {
std::vector<int> mults; std::map<std::tuple<int, int>, int> mults{};
explicit Multiplicites(const std::vector<Mult> &vals) {
mults = std::vector<int>(N * (N - 1) / 2, 2);
for (const auto &mult : vals) {
set(mult.a, mult.b, mult.mult);
}
}
void set(int a, int b, int mult) { void set(int a, int b, int mult) {
if (a > N or b > N) throw std::logic_error("mirror does not exist"); if (a > b) std::swap(a, b);
if (a == b) throw std::logic_error("cannot compare mirror to itself"); mults[std::make_tuple(a, b)] = mult;
if (a < b) std::swap(a, b); // a is bigger
mults[a + b] = mult;
} }
[[nodiscard]] int get(int a, int b) const { [[nodiscard]] int get(int a, int b) const {
if (a > N or b > N) throw std::logic_error("mirror does not exist"); if (a == b) return 1;
if (a == b) throw std::logic_error("cannot compare mirror to itself"); if (a > b) std::swap(a, b);
if (a < b) std::swap(a, b); // a is bigger
return mults[a + b]; const auto &tup = std::make_tuple(a, b);
const auto &res = mults.find(tup);
if (res == mults.end()) return 2;
return res->second;
}
[[nodiscard]] std::vector<int> relation(int a, int b) const {
std::vector<int> res{};
int mult = get(a, b);
for (int i = 0; i < mult; ++i) {
res.push_back(a);
res.push_back(b);
}
return res;
}
[[nodiscard]] std::vector<std::vector<int>> relations() const {
std::vector<std::vector<int>> res{};
for (int a = 0; a < N; ++a) {
for (int b = a; b < N; ++b) {
res.push_back(relation(a, b));
}
}
return res;
} }
}; };
template<int N>
Mults<N> schlafli(const int (&symbol)[N - 1]) {
Mults<N> mults{};
for (int i = 0; i < N; ++i) {
mults.set(i, i + 1, symbol[i]);
}
return mults;
}
struct Table { struct Table {
int N; int N;
@@ -171,7 +192,10 @@ std::ostream &operator<<(std::ostream &out, const Row &row) {
return out; return out;
} }
Table *solve(int gens, const std::vector<int> &subgens, const std::vector<std::vector<int>> &rels) { template<int N>
Table *solve(const std::vector<int> &subgens, const Mults<N> &mults) {
const auto rels = mults.relations();
int gens = N;
auto *table = new Table(gens); auto *table = new Table(gens);
for (int gen : subgens) for (int gen : subgens)

View File

@@ -7,58 +7,44 @@
#include <vector> #include <vector>
template<int N> template<int N>
std::vector<glm::vec4> std::vector<std::vector<int>> coxeter_rels() {
vertices(const std::vector<int> &subgens, const Multiplicites<N> &mults, const float (&coords)[N]) {
std::vector<std::vector<int>> rels{}; std::vector<std::vector<int>> rels{};
rels.reserve(N + N * (N - 1) / 2);
for (int i = 0; i < N; ++i) { return rels;
rels.push_back({i, i}); }
}
for (int a = 0; a < N; ++a) {
for (int b = 0; b < a; ++b) {
int mult = mults.get(a, b);
std::vector<int> rel{}; template<int N>
for (int i = 0; i < mult; ++i) { glm::vec4 identity(const std::vector<glm::vec4> &normals, const float(&coords)[N]) {
rel.push_back(a); const std::vector<glm::vec4> corners = plane_intersections(normals);
rel.push_back(b);
}
rels.push_back(rel);
}
}
Table *table = solve(N, subgens, rels);
// std::cout << table->size() << std::endl;
// std::cout << *table << std::endl;
// for (const auto &v : table->words()) {
// std::cout << "[ ";
// for (auto e : v) {
// std::cout << e << " ";
// }
// std::cout << "]\n";
// }
const std::vector<glm::vec4> &normals = mirror<3>(mults);
const std::vector<glm::vec4> &corners = plane_intersections(normals);
const std::vector<float> coords_vec(coords, coords + N); const std::vector<float> coords_vec(coords, coords + N);
const glm::vec4 &identity = glm::normalize(barycentric(corners, coords_vec)); const glm::vec4 identity = barycentric(corners, coords_vec);
return glm::normalize(identity);
}
template<int N>
std::vector<glm::vec4>
vertices(const Mults<N> &mults, const float (&coords)[N]) {
Table *table = solve({}, mults);
const std::vector<glm::vec4> normals = mirror<N>(mults);
glm::vec4 ident = identity(normals, coords);
std::vector<glm::vec4> verts{}; std::vector<glm::vec4> verts{};
for (const auto &word : table->words()) { for (const auto &word : table->words()) {
glm::vec4 vert = identity; glm::vec4 vert = ident;
for (const auto &gen : word) { for (const auto &gen : word) {
vert = reflect(vert, normals[gen]); vert = reflect(vert, normals[gen]);
} }
verts.push_back(vert); verts.push_back(vert);
} }
for (const auto &e : corners) {
verts.push_back(e * 1.1f);
}
return verts; return verts;
} }
template<int N>
std::vector<unsigned> lines(const Mults<N> &mults) {
// Table *table = solve(N, {}, coxeter_rels(mults));
return {};
}

View File

@@ -11,7 +11,7 @@
#include "coxeter.hpp" #include "coxeter.hpp"
template<int N> template<int N>
std::vector<glm::vec4> mirror(const Multiplicites<N> &mults) { std::vector<glm::vec4> mirror(const Mults<N> &mults) {
static_assert(1 <= N and N <= 4, "Vector size is unsupported"); static_assert(1 <= N and N <= 4, "Vector size is unsupported");
std::vector<glm::vec4> mirrors{}; std::vector<glm::vec4> mirrors{};