Broken 120-cell
This commit is contained in:
		
							parent
							
								
									c986b7cbfb
								
							
						
					
					
						commit
						3ba81a2f83
					
				@ -3,7 +3,7 @@ import * as THREE from 'three';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const HYPERPLANE = 2;
 | 
					const HYPERPLANE = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const NODE_SIZE = 0.08;
 | 
					const NODE_SIZE = 0.02;
 | 
				
			||||||
const LINK_SIZE = 0.02;
 | 
					const LINK_SIZE = 0.02;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.js
									
									
									
									
									
								
							@ -7,7 +7,7 @@ import { FourDShape } from './fourDShape.js';
 | 
				
			|||||||
import { GUI } from 'lil-gui';
 | 
					import { GUI } from 'lil-gui';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const DEFAULT_SHAPE = '16-cell';
 | 
					const DEFAULT_SHAPE = '120-cell';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// hacky stuff for 4d rotations
 | 
					// hacky stuff for 4d rotations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -120,7 +120,7 @@ const LINK_OPACITY = 0.7;
 | 
				
			|||||||
// 2 M    2 (0-2) B
 | 
					// 2 M    2 (0-2) B
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const node_ms = [
 | 
					const node_ms = [
 | 
				
			||||||
	new THREE.MeshStandardMaterial( { color: 0x707070 } ),
 | 
						new THREE.MeshStandardMaterial( { color: 0xc0c0c0 } ),
 | 
				
			||||||
	new THREE.MeshStandardMaterial( { color: 0x20dddd } ),
 | 
						new THREE.MeshStandardMaterial( { color: 0x20dddd } ),
 | 
				
			||||||
	new THREE.MeshStandardMaterial( { color: 0xdddd20 } ),
 | 
						new THREE.MeshStandardMaterial( { color: 0xdddd20 } ),
 | 
				
			||||||
	new THREE.MeshStandardMaterial( { color: 0xdd20dd } ),
 | 
						new THREE.MeshStandardMaterial( { color: 0xdd20dd } ),
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										80
									
								
								permute.js
									
									
									
									
									
								
							
							
						
						
									
										80
									
								
								permute.js
									
									
									
									
									
								
							@ -86,14 +86,14 @@ function permutations_even(a) {
 | 
				
			|||||||
// [ [1, 1, 0, 0 ], [ -1, 1, 0, 0 ], [ 1, -1, 0, 0 ], [-1, -1, 0, 0 ]]
 | 
					// [ [1, 1, 0, 0 ], [ -1, 1, 0, 0 ], [ 1, -1, 0, 0 ], [-1, -1, 0, 0 ]]
 | 
				
			||||||
// ie don't do it on the zeros
 | 
					// ie don't do it on the zeros
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function expand_sign(a) {
 | 
					function expand_sign(a, label) {
 | 
				
			||||||
	const expanded = [];
 | 
						const expanded = [];
 | 
				
			||||||
	const exv = a.map((v) => v ? [ -v, v ] : [ 0 ]);
 | 
						const exv = a.map((v) => v ? [ -v, v ] : [ 0 ]);
 | 
				
			||||||
	for( const xv of exv[0] ) {
 | 
						for( const xv of exv[0] ) {
 | 
				
			||||||
		for( const yv of exv[1] ) {
 | 
							for( const yv of exv[1] ) {
 | 
				
			||||||
			for( const zv of exv[2] ) {
 | 
								for( const zv of exv[2] ) {
 | 
				
			||||||
				for( const wv of exv[3] ) {
 | 
									for( const wv of exv[3] ) {
 | 
				
			||||||
					expanded.push({x: xv, y:yv, z:zv, w:wv});
 | 
										expanded.push({label: label, x: xv, y:yv, z:zv, w:wv});
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -102,14 +102,86 @@ function expand_sign(a) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function coordinates(a, even=false) {
 | 
					export function coordinates(a, id0=1, even=false) {
 | 
				
			||||||
	const ps = even ? permutations_even(a) : permutations(a);
 | 
						const ps = even ? permutations_even(a) : permutations(a);
 | 
				
			||||||
	const coords = [];
 | 
						const coords = [];
 | 
				
			||||||
	for( const p of ps ) {
 | 
						for( const p of ps ) {
 | 
				
			||||||
		const expanded = expand_sign(p);
 | 
							const expanded = expand_sign(p, 0);
 | 
				
			||||||
		coords.push(...expanded);
 | 
							coords.push(...expanded);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return coords;
 | 
						return coords;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function scale_and_index(nodes, scale) {
 | 
				
			||||||
 | 
						let i = 1;
 | 
				
			||||||
 | 
						for( const n of nodes ) {
 | 
				
			||||||
 | 
							n["id"] = i;
 | 
				
			||||||
 | 
							i++;
 | 
				
			||||||
 | 
							for( const a of [ 'x', 'y', 'z', 'w' ] ) {
 | 
				
			||||||
 | 
								n[a] = scale * n[a];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nodes;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function make_120cell_vertices() {
 | 
				
			||||||
 | 
						const phi = 0.5 * (1 + Math.sqrt(5));  
 | 
				
			||||||
 | 
						const r5 = Math.sqrt(5);   
 | 
				
			||||||
 | 
						const phi2 = phi * phi;    
 | 
				
			||||||
 | 
						const phiinv = 1 / phi;    
 | 
				
			||||||
 | 
						const phi2inv = 1 / phi2;  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const nodes = [
 | 
				
			||||||
 | 
							coordinates([2, 2, 0, 0],  0),
 | 
				
			||||||
 | 
							coordinates([r5, 1, 1, 1], 1),
 | 
				
			||||||
 | 
							coordinates([phi, phi, phi, phi2inv], 2),
 | 
				
			||||||
 | 
							coordinates([phi, phiinv, phiinv, phiinv], 0),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							coordinates([phi2, phi2inv, 1, 0], 1, true),
 | 
				
			||||||
 | 
							coordinates([r5, phiinv, phi, 0], 2, true),
 | 
				
			||||||
 | 
							coordinates([2, 1, phi, phiinv], 0, true),
 | 
				
			||||||
 | 
							].flat();
 | 
				
			||||||
 | 
						return scale_and_index(nodes, 0.5);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function dist2(n1, n2) {
 | 
				
			||||||
 | 
						return (n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2 + (n1.z - n2.z) ** 2 + (n1.w - n2.w) ** 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function make_120cell_edges(nodes) {
 | 
				
			||||||
 | 
						const seen = {};
 | 
				
			||||||
 | 
						const nnodes = nodes.length;
 | 
				
			||||||
 | 
						const links = [];
 | 
				
			||||||
 | 
						let id = 1;
 | 
				
			||||||
 | 
						for( let i = 0; i < nnodes - 1; i++ ) {
 | 
				
			||||||
 | 
							const d2 = [];
 | 
				
			||||||
 | 
							for( let j = 0; j < nnodes; j++ ) {
 | 
				
			||||||
 | 
								d2.push({ d2: dist2(nodes[i], nodes[j]), id: j });
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							d2.sort((a, b) => b.d2 - a.d2);
 | 
				
			||||||
 | 
							const closest = d2.slice(1, 4);
 | 
				
			||||||
 | 
							for( const e in closest ) {
 | 
				
			||||||
 | 
								const ids = [ nodes[i].id, e.id ];
 | 
				
			||||||
 | 
								ids.sort();
 | 
				
			||||||
 | 
								const fp = ids.join(',');
 | 
				
			||||||
 | 
								if( !seen[fp] ) {
 | 
				
			||||||
 | 
									seen[fp] = true;
 | 
				
			||||||
 | 
									links.push({ id: id, label: 0, source: nodes[i].id, target: e.id });
 | 
				
			||||||
 | 
									id++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return links;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const nodes  = make_120cell_vertices();
 | 
				
			||||||
 | 
					const links = make_120cell_edges(nodes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log(links);
 | 
				
			||||||
							
								
								
									
										82
									
								
								polytopes.js
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								polytopes.js
									
									
									
									
									
								
							@ -1,6 +1,19 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import * as PERMUTE from './permute.js';
 | 
					import * as PERMUTE from './permute.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function scale_and_index(nodes, scale) {
 | 
				
			||||||
 | 
						let i = 1;
 | 
				
			||||||
 | 
						for( const n of nodes ) {
 | 
				
			||||||
 | 
							n["id"] = i;
 | 
				
			||||||
 | 
							i++;
 | 
				
			||||||
 | 
							for( const a of [ 'x', 'y', 'z', 'w' ] ) {
 | 
				
			||||||
 | 
								n[a] = scale * n[a];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nodes;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const cell5 = () => {
 | 
					export const cell5 = () => {
 | 
				
			||||||
	const r5 = Math.sqrt(5);
 | 
						const r5 = Math.sqrt(5);
 | 
				
			||||||
	const r2 = Math.sqrt(2) / 2;
 | 
						const r2 = Math.sqrt(2) / 2;
 | 
				
			||||||
@ -232,38 +245,67 @@ export const cell24 = () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function make_120cell_vertices() {
 | 
					function make_120cell_vertices() {
 | 
				
			||||||
	const phi = 0.5 * (1 + Math.sqrt(5));  3
 | 
						const phi = 0.5 * (1 + Math.sqrt(5));  
 | 
				
			||||||
	const r5 = Math.sqrt(5);   5
 | 
						const r5 = Math.sqrt(5);   
 | 
				
			||||||
	const phi2 = phi * phi;    4
 | 
						const phi2 = phi * phi;    
 | 
				
			||||||
	const phiinv = 1 / phi;    6
 | 
						const phiinv = 1 / phi;    
 | 
				
			||||||
	const phi2inv = 1 / phi2;  7
 | 
						const phi2inv = 1 / phi2;  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const nodes = [
 | 
						const nodes = [
 | 
				
			||||||
		PERMUTE.coordinates([2, 2, 0, 0]),
 | 
							PERMUTE.coordinates([2, 2, 0, 0],  0),
 | 
				
			||||||
		PERMUTE.coordinates([r5, 1, 1, 1]),
 | 
							PERMUTE.coordinates([r5, 1, 1, 1], 1),
 | 
				
			||||||
		PERMUTE.coordinates([phi, phi, phi, phi2inv]),
 | 
							PERMUTE.coordinates([phi, phi, phi, phi2inv], 2),
 | 
				
			||||||
		PERMUTE.coordinates([phi, phiinv, phiinv, phiinv]),
 | 
							PERMUTE.coordinates([phi, phiinv, phiinv, phiinv], 0),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		PERMUTE.coordinates([phi2, phi2inv, 1, 0], true),
 | 
							PERMUTE.coordinates([phi2, phi2inv, 1, 0], 1, true),
 | 
				
			||||||
		PERMUTE.coordinates([r5, phiinv, phi, 0], true),
 | 
							PERMUTE.coordinates([r5, phiinv, phi, 0], 2, true),
 | 
				
			||||||
		PERMUTE.coordinates([2, 1, phi, phiinv], true),
 | 
							PERMUTE.coordinates([2, 1, phi, phiinv], 0, true),
 | 
				
			||||||
		].flat();
 | 
							].flat();
 | 
				
			||||||
	let i = 1;
 | 
						return scale_and_index(nodes, 0.5);
 | 
				
			||||||
	for( const n of nodes ) {
 | 
					 | 
				
			||||||
		n["id"] = i;
 | 
					 | 
				
			||||||
		i++;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nodes;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function dist2(n1, n2) {
 | 
				
			||||||
 | 
						return (n1.x - n2.x) ** 2 + (n1.y - n2.y) ** 2 + (n1.z - n2.z) ** 2 + (n1.w - n2.w) ** 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function make_120cell_edges(nodes) {
 | 
				
			||||||
 | 
						const seen = {};
 | 
				
			||||||
 | 
						const nnodes = nodes.length;
 | 
				
			||||||
 | 
						const links = [];
 | 
				
			||||||
 | 
						let id = 1;
 | 
				
			||||||
 | 
						for( const n1 of nodes ) {
 | 
				
			||||||
 | 
							console.log(n1);
 | 
				
			||||||
 | 
							const d2 = [];
 | 
				
			||||||
 | 
							for( const n2 of nodes ) {
 | 
				
			||||||
 | 
								d2.push({ d2: dist2(n1, n2), id: n2.id });
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							d2.sort((a, b) => a.d2 - b.d2);
 | 
				
			||||||
 | 
							const closest = d2.slice(1, 5);
 | 
				
			||||||
 | 
							for( const e of closest ) {
 | 
				
			||||||
 | 
								const ids = [ n1.id, e.id ];
 | 
				
			||||||
 | 
								ids.sort();
 | 
				
			||||||
 | 
								const fp = ids.join(',');
 | 
				
			||||||
 | 
								if( !seen[fp] ) {
 | 
				
			||||||
 | 
									seen[fp] = true;
 | 
				
			||||||
 | 
									links.push({ id: id, label: 0, source: n1.id, target: e.id });
 | 
				
			||||||
 | 
									id++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return links;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const cell120 = () => {
 | 
					export const cell120 = () => {
 | 
				
			||||||
	const nodes  = make_120cell_vertices();
 | 
						const nodes  = make_120cell_vertices();
 | 
				
			||||||
 | 
						const links = make_120cell_edges(nodes);
 | 
				
			||||||
	return {
 | 
						return {
 | 
				
			||||||
		nodes: nodes,
 | 
							nodes: nodes,
 | 
				
			||||||
		links: []
 | 
							links: links
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const nodes = cell120();
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user