Got the vertices of the 120-cell looking ok

feature-big-polytopes
Mike Lynch 2023-07-27 15:06:25 +10:00
parent 32a01e6bfd
commit c986b7cbfb
3 changed files with 90 additions and 3 deletions

View File

@ -157,6 +157,7 @@ const STRUCTURES = {
'16-cell': POLYTOPES.cell16(),
'tesseract': POLYTOPES.tesseract(),
'24-cell': POLYTOPES.cell24(),
'120-cell': POLYTOPES.cell120()
};
console.log(STRUCTURES);
@ -167,7 +168,7 @@ function createShape(name) {
if( shape ) {
scene.remove(shape);
}
console.log(STRUCTURES[name]);
shape = new FourDShape(node_ms, link_ms, STRUCTURES[name]);
scene.add(shape);
@ -219,7 +220,7 @@ const gui_params = {
};
gui.add(gui_params, 'shape',
[ '5-cell', '16-cell', 'tesseract', '24-cell' ]
[ '5-cell', '16-cell', 'tesseract', '24-cell', '120-cell' ]
).onChange(createShape)
gui.add(gui_params, 'hyperplane', 1.5, 4);

View File

@ -28,15 +28,32 @@ function pandita(a) {
return false;
}
function permutations_old(a) {
a.sort();
const ps = [ [...a] ];
let running = true;
while( running ) {
const s = pandita(a);
if( s ) {
ps.push([...a]);
} else {
running = false;
}
}
return ps;
}
function permutations(a) {
a.sort();
const ps = [ [...a] ];
while( pandita(a) ) {
let running = true;
while( pandita(a) > 0 ) {
ps.push([...a]);
}
return ps;
}
function permutations_even(a) {
a.sort();
let parity = 'even';
@ -64,4 +81,35 @@ function permutations_even(a) {
return ps;
}
// for a given permutation, say [ 1, 1, 0, 0 ], return all
// of the valid changes of sign, so:
// [ [1, 1, 0, 0 ], [ -1, 1, 0, 0 ], [ 1, -1, 0, 0 ], [-1, -1, 0, 0 ]]
// ie don't do it on the zeros
function expand_sign(a) {
const expanded = [];
const exv = a.map((v) => v ? [ -v, v ] : [ 0 ]);
for( const xv of exv[0] ) {
for( const yv of exv[1] ) {
for( const zv of exv[2] ) {
for( const wv of exv[3] ) {
expanded.push({x: xv, y:yv, z:zv, w:wv});
}
}
}
}
return expanded;
}
export function coordinates(a, even=false) {
const ps = even ? permutations_even(a) : permutations(a);
const coords = [];
for( const p of ps ) {
const expanded = expand_sign(p);
coords.push(...expanded);
}
return coords;
}

View File

@ -1,4 +1,5 @@
import * as PERMUTE from './permute.js';
export const cell5 = () => {
const r5 = Math.sqrt(5);
@ -229,3 +230,40 @@ export const cell24 = () => {
};
}
function make_120cell_vertices() {
const phi = 0.5 * (1 + Math.sqrt(5)); 3
const r5 = Math.sqrt(5); 5
const phi2 = phi * phi; 4
const phiinv = 1 / phi; 6
const phi2inv = 1 / phi2; 7
const nodes = [
PERMUTE.coordinates([2, 2, 0, 0]),
PERMUTE.coordinates([r5, 1, 1, 1]),
PERMUTE.coordinates([phi, phi, phi, phi2inv]),
PERMUTE.coordinates([phi, phiinv, phiinv, phiinv]),
PERMUTE.coordinates([phi2, phi2inv, 1, 0], true),
PERMUTE.coordinates([r5, phiinv, phi, 0], true),
PERMUTE.coordinates([2, 1, phi, phiinv], true),
].flat();
let i = 1;
for( const n of nodes ) {
n["id"] = i;
i++;
}
return nodes;
}
export const cell120 = () => {
const nodes = make_120cell_vertices();
return {
nodes: nodes,
links: []
}
}