[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: More Polychora #16

Open
mikehdugeo opened this issue Dec 14, 2023 · 4 comments
Open

FR: More Polychora #16

mikehdugeo opened this issue Dec 14, 2023 · 4 comments
Labels

Comments

@mikehdugeo
Copy link

There are three classes of n-dimensional regular polytopes ("polyhedra") that exist for all n: the hypercube, its dual the cross-polytope, and the simplex (the n-D analogues of the cube, octahedron and tetrahedron)

There are also a handful of regular polytopes that only exist for specific n:

  • polygons in 2D
  • the icosahedron and dodecahedron in 3D
  • in 4D: the 120-cell (which has dodecahedral facets, so it's kind of an analogue of the dodecahedron), the 600-cell (its dual, kind of an analogue of the icosahedron) and the 24-cell (a beautiful shape with octahedral facets).

It would be nice to be able to visualise these too. I'm happy to provide any necessary info about the coordinates of the vertices and which ones connect to form edges and faces, but I don't know Rust.

Be warned though that this is a can of worms - there are many many many interesting less regular shapes people might like to see visualised, (eg, the 4D or higher equivalents of the archimedean solids)

@ndavd ndavd added the enhancement New feature or request label Dec 14, 2023
@ndavd
Copy link
Owner
ndavd commented Dec 14, 2023

Thanks for the feature request.

Currently I have a few more pressing and quicker feature requests to solve. And like you said it's can of worms.

That being said, eventually, I would consider that. I'd like to see more than hypercubes, make this the tool to visualize and interact with higher dimensional objects. But before that I'd even prefer to refactor the whole thing and make it the most performant possible, before adding even more objects.

But feel free to continue the discussion here in the meantime, give examples, perhaps make a list even, and the respective coordinates would be appreciated. So that by the time ncube is ready for this a plan has been devised and there's less time researching about the polyhedra.

@mikehdugeo
Copy link
Author

For the sporadic examples (the 24-cell, 120-cell and 600-cell), I could make a PR with text files of the coordinates, edges, 2-faces and 3-faces. Then you'd have them in your repository.

For the general classes I could just describe here the algorithms for generating the coordinates.

What do you think?

@ndavd
Copy link
Owner
ndavd commented Dec 15, 2023

There's a rule on how ncube works. From the README:

Everything is generated in real time just from the dimension number.

I've made that decision before writing a single line of code, it's much harder to implement but has a few much desired advantages: No typos in hardcoded data, can scale to any (n) dimensions.

That being said, for adding new objects it would need to look something like this:

  • There must be an object of that type in each dimension (or several). If you have an object in mind you must ask the following, does it have a corresponding object in all other dimensions?
  • I'll still need the coordinates to check. Will, hovever, just be used in tests so if you can just share them here.
  • Will need the total number of vertices, edges and faces in each dimension or a formula for those if you happen to know it.

@mikehdugeo
Copy link
Author

Everything is generated in real time just from the dimension number.

This works for the n-cross polytope and the n-simplex, but not for regular figures in general.

It maybe kinda-sorta works for the 24-cell, but it's only regular for n=4. I'm not sure if there's a sensible, intuitive general family of shapes that include the 600-cell (or the 120-cell), but if there is, they'd only be regular for n=4 (and maybe n=3 if these families include the icosahedron and dodecahedron).

Anyway: for the n-cross:

  • The 2n vertices are e_i and -e_i, where e_i are the axis vectors. Eg, for the octahedron (the 3-cross), they are (1,0,0), (0,1,0), (0,0,1), (-1,0,0), (0,-1,0), (0,0,-1).
  • Two vertices have an edge joining them if and only if their dot product is 0.
  • In general, k vertices are all on a common (k-1)-dimensional face, if every pair of them has dot product 0.
  • The number of k-faces (k-dimensional faces) of an n-cross is equal to the number of (n-1-k)-faces of the n-cube. Eg, in 5D, the 5-cube has 32 vertices, 80 edges, 80 2D faces, 40 3D faces and 10 4D faces... but the 5-cross has 10 vertices, 40 edges, 80 2D faces, 80 3D faces and 32 4D faces.
    ==============

The n-simplex has n+1 vertices, and they're all connected by edges. Every set of k+1 vertices forms a k-dimensional face. So, there are choose(n+1, k+1) faces of dimension k.

To construct the vertices, there are two ways (which will give different answers, but the answers will be scaled rotated versions of each other)

Method 1: recursively:

The vertices of a 1-dimensional simplex are (-0.5) and (0.5).

Given the n vertices (...v1...), (...v2...) ... (...vn...) etc of an n-1 dimensional simplex, the n+1 vertices of an n-dimensional simplex are:

  • (...v1..., -xn), (...v1..., -xn), ... (...vn..., -xn) ....... that is, shift the n vertices a distance xn (defined below) down the new axis
  • (0,0,....,0,n*xn).

where xn = 1 / sqrt( 2 * n * (n+1) )

Eg, given the vertices (-1/2), (1/2) of the 1D simplex:

  • x2 is 1 / sqrt(12)
  • the vertices of the 2D simplex (equilateral triangle) are [-1/2, -1/sqrt(12)], [1/2, -1/sqrt(12)], [0, 2/sqrt(12)]
  • x3 is 1 / sqrt(24)
  • the vertices of the 3D simplex (tetrahedron) are [-1/2, -1/sqrt(12), -1/sqrt(24)], [1/2, -1/sqrt(12), -1/sqrt(24)], [0, 2/sqrt(12), -1/sqrt(24)], [0, 0, 3/sqrt(24)]
  • x4 is 1 / sqrt(40)
  • the vertices of the 3D simplex (tetrahedron) are [-1/2, -1/sqrt(12), -1/sqrt(24), -1/sqrt(40)], [1/2, -1/sqrt(12), -1/sqrt(24), -1/sqrt(40)], [0, 2/sqrt(12), -1/sqrt(24), -1/sqrt(40)], [0, 0, 3/sqrt(24), -1/sqrt(40)], [0, 0, 0, 4/sqrt(40)]

Sanity checks:

  • All points should be the same distance from 0
  • All pairs of points should be 1 unit apart

Method 2: vector projection

To construct the set of

  • Let v_i = e_i, the n+1 basis vectors of (n+1)-dimensional space
  • Use the Gram-Schmidt process to find an orthonormal basis b0, b1, b2...., bn for (n+1)-dimensional space that has b0 = (1,1,1,....,1,1) / (n+1)
  • The coordinates of the vertices are (vi . b1, vi . b2, vi . b3, .... , vi . bn) for i from 1 to (n+1). Note that b0 is not used.

Sanity checks:

  • All points should be the same distance from 0
  • All pairs of points should be sqrt(2) units apart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants