We have updated the 3D visualizer to include interactive controls and floor scaling.
import * as THREE from 'https://unpkg.com/three@latest/build/three.module.js?module';
import { OrbitControls } from 'https://unpkg.com/three@latest/examples/jsm/controls/OrbitControls.js?module';
// Golden Ratio and Scaling function
const PHI = (1 + Math.sqrt(5)) / 2;
const sqrt5 = Math.sqrt(5);
function transformCoord(k) {
return (Math.round(k / PHI) + k * PHI) / sqrt5;
}
// Generate Icosahedron Vertices with Circular Permutations
const baseVertices = [
[0, 2, 1], [0, -2, 1], [0, -2, -1], [0, 2, -1]
];
const icoVertices = [];
baseVertices.forEach(v => {
icoVertices.push(v);
icoVertices.push([v[1], v[2], v[0]]);
icoVertices.push([v[2], v[0], v[1]]);
});
// Transform coordinates
const vertices = icoVertices.map(v => v.map(transformCoord));
// Floor and Ceiling Hexagons
//const scaleMap = { 1: 3, 2: 5, -1: -3, -2: -5 };
const hexagonBase = [
[0, 5, -3], [4, 1, -3], [4, -1, -3],
[0, -5, -3], [-4, -1, -3], [-4, 1, -3]
].map(v => v.map(transformCoord));
const hexagonTop = hexagonBase.map(v => [v[0], v[1], transformCoord(3)]);
// Initialize Three.js Scene
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 10;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Create Icosahedron Geometry
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(vertices.flat());
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
const material = new THREE.MeshBasicMaterial({ color: 0xff0000, wireframe: true });
const icosahedron = new THREE.Mesh(geometry, material);
scene.add(icosahedron);
// Floor and Ceiling Hexagons
function createHexagon(hexagonVertices, color) {
const hexGeometry = new THREE.BufferGeometry();
const hexPoints = hexagonVertices.map(v => new THREE.Vector3(...v));
hexGeometry.setFromPoints(hexPoints);
const hexMaterial = new THREE.LineBasicMaterial({ color });
const hexMesh = new THREE.LineLoop(hexGeometry, hexMaterial);
scene.add(hexMesh);
}
createHexagon(hexagonBase, 0x0000ff); // Floor in Blue
createHexagon(hexagonTop, 0xff0000); // Ceiling in Red
// Controls
const controls = new OrbitControls(camera, renderer.domElement);
// Animation loop
function animate() {
requestAnimationFrame(animate);
icosahedron.rotation.x += 0.01;
icosahedron.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();