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);
verts_data = vertices<3>({}, Multiplicites<3>({
{0, 1, 5},
{1, 2, 3}
}), {
10, 1, 1
});
verts_data = vertices<3>(
schlafli<3>({5, 3}),
{10, 1, 1});
glGenBuffers(1, &verts);
glBindBuffer(GL_ARRAY_BUFFER, verts);
@@ -81,9 +78,7 @@ public:
glBindVertexArray(tri);
glUniform4f(0, 1, 1, 1, 1);
glDrawArrays(GL_POINTS, 0, verts_data.size() - 3);
glUniform4f(0, 1, 1, 1, .1);
glDrawArrays(GL_TRIANGLES, verts_data.size() - 3, 3);
glDrawArrays(GL_POINTS, 0, verts_data.size());
swapbuffers();
}

View File

@@ -1,16 +1,20 @@
#include "util/mesh.hpp"
int main(int argc, char *argv[]) {
auto vs = vertices<3>({}, Multiplicites<3>({
{0, 1, 4},
{1, 2, 3}
}), {
1.0f, 1.0f, 1.0f
});
const auto &mults = schlafli<4>({4, 3, 3});
const std::vector<glm::vec4> &vs = vertices<4>(mults, {10, 1, 1, 1});
for (const auto &v : vs) {
for (const auto &v:vs) {
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"
int main(int argc, char *argv[]) {
auto normals = mirror<3>(Multiplicites<3>({
auto normals = mirror<3>(Multiplicities<3>({
{0, 1, 4},
{1, 2, 3}
}));

View File

@@ -5,39 +5,60 @@
#include <iomanip>
#include <algorithm>
#include <cmath>
struct Mult {
int a, b, mult;
};
#include <map>
#include <tuple>
template<int N>
struct Multiplicites {
std::vector<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);
}
}
struct Mults {
std::map<std::tuple<int, int>, int> mults{};
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) throw std::logic_error("cannot compare mirror to itself");
if (a < b) std::swap(a, b); // a is bigger
mults[a + b] = mult;
if (a > b) std::swap(a, b);
mults[std::make_tuple(a, b)] = mult;
}
[[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) throw std::logic_error("cannot compare mirror to itself");
if (a < b) std::swap(a, b); // a is bigger
if (a == b) return 1;
if (a > b) std::swap(a, b);
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 {
int N;
@@ -171,7 +192,10 @@ std::ostream &operator<<(std::ostream &out, const Row &row) {
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);
for (int gen : subgens)

View File

@@ -7,58 +7,44 @@
#include <vector>
template<int N>
std::vector<glm::vec4>
vertices(const std::vector<int> &subgens, const Multiplicites<N> &mults, const float (&coords)[N]) {
std::vector<std::vector<int>> coxeter_rels() {
std::vector<std::vector<int>> rels{};
rels.reserve(N + N * (N - 1) / 2);
for (int i = 0; i < N; ++i) {
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);
return rels;
}
std::vector<int> rel{};
for (int i = 0; i < mult; ++i) {
rel.push_back(a);
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);
template<int N>
glm::vec4 identity(const std::vector<glm::vec4> &normals, const float(&coords)[N]) {
const std::vector<glm::vec4> corners = plane_intersections(normals);
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{};
for (const auto &word : table->words()) {
glm::vec4 vert = identity;
glm::vec4 vert = ident;
for (const auto &gen : word) {
vert = reflect(vert, normals[gen]);
}
verts.push_back(vert);
}
for (const auto &e : corners) {
verts.push_back(e * 1.1f);
}
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"
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");
std::vector<glm::vec4> mirrors{};