import * as POLYTOPES from './polytopes.js'; // exploring more inscriptions of the 120-cell export function nodes_links(links, nodeid) { return links.filter((l) => l.source === nodeid || l.target === nodeid); } export function linked(links, n1, n2) { const ls = nodes_links(nodes_links(links, n1), n2); if( ls.length ) { return ls[0] } else { return false; } } function fingerprint(ids) { const sids = [...ids]; sids.sort(); return sids.join(','); } export function dist(n1, n2) { return Math.sqrt((n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2 + (n1.z - n2.z) ** 2 + (n1.w - n2.w) ** 2); } export function make_120cell() { const nodes = POLYTOPES.make_120cell_vertices(); const links = POLYTOPES.auto_detect_edges(nodes, 4); return { nodes: nodes, links: links } } function round_dist(raw) { return Math.floor(raw * 100000) / 100000; } export function distance_groups(cell120) { // get list of other nodes by distance // sort them and dump them out const dists = {}; cell120.nodes.map((n) => { const draw = dist(cell120.nodes[0], n); const dtrunc = round_dist(draw); if( !(dtrunc in dists) ) { dists[dtrunc] = []; } dists[dtrunc].push(n); }); return dists; } function distance_group(cell120, n0, chord) { const nodes = [] cell120.nodes.map((n) => { const d = round_dist(dist(n0, n)); if( d == chord ) { nodes.push(n); } }); // filter and return those whose chord is also the same const equidistant = []; for( const n1 of nodes ) { for( const n2 of nodes ) { if( n2.id > n1.id ) { if( round_dist(dist(n1, n2)) == chord ) { equidistant.push([n1, n2]); } } } } return equidistant; } export function chord_survey() { const cell120 = POLYTOPES.cell120_inscribed(); const dgroups = distance_groups(cell120); const dists = Object.keys(dgroups); dists.sort(); for( const d of dists ) { const g0 = dgroups[d][0]; dgroups[d].map((g) => { console.log(`${g0.id}-${g.id}: ${round_dist(dist(g0, g))}`); }); } } function overlap(c1, c2) { for( const l in c1 ) { if( c1[l] === c2[l] ) { return true; } } return false; } export function gather_5cells(cell120) { const CHORD5 = round_dist(Math.sqrt(2.5)); const bins = []; const all = []; cell120.nodes.filter((n) => n.label === 1).map((n) => { const cells = [ ]; const g = distance_group(cell120, n, CHORD5); for( const pair of g ) { let seen = false; for( const cell of cells ) { const c = Object.values(cell); if( c.includes(pair[0].id) || c.includes(pair[1].id) ) { if( !c.includes(pair[0].id) ) { cell[pair[0].label] = pair[0].id; } if( !c.includes(pair[1].id) ) { cell[pair[1].label] = pair[1].id; } seen = true; break; } } if( !seen ) { const cell = {}; cell[1]= n.id; cell[pair[0].label] = pair[0].id; cell[pair[1].label] = pair[1].id; cells.push(cell); } } all.push(...cells); }); return all; } function audit_5cells(cells) { // this verifies that for each label (a 600-cell set), each of its // vertices is in exactly 7 5-cells. It checks out. ['1','2','3','4','5'].map((l) => { const sets = {}; for( const cell of cells ) { const lv = cell[l]; if( !(lv in sets) ) { sets[lv] = []; } sets[lv].push(cell); } for( const lv in sets ) { const ok = ( sets[lv].length === 7 ) ? 'ok' : 'miss'; console.log(`${l},${lv},${sets[lv].length},${ok}`); } }); } function try_120_5_cells(cell120, cells, l) { // iterate over every vertex in the 600-cell defined by label l, // get all 7 5-cells including that vertex, and add them if they are // disjoint with what we already have const vertices = cell120.nodes.filter((n) => n.label === l); const cellset = []; for( const v of vertices ) { console.log(`Vertex ${v.id}`); const vcells = cells.filter((c) => c[l] === v.id); const overlap_any = (cs, c) => { for( const seen of cs ) { console.log(c); if( overlap(seen, c) ) { console.log("overlap"); console.log(seen); console.log(c); return true; } } return false; } const disjoint = vcells.filter((c) => ! overlap_any(cellset, c)); console.log(`Found ${disjoint.length} disjoint cells`); if( disjoint.length > 0 ) { cellset.push(disjoint[0]); } } console.log(`Found total of ${cellset.length} disjoint cells`); //console.log(cellset); } const cell120 = POLYTOPES.cell120_inscribed(); const all5 = gather_5cells(cell120); try_120_5_cells(cell120, all5, 1);