-
Notifications
You must be signed in to change notification settings - Fork 6
/
stereo.html
203 lines (159 loc) · 6.36 KB
/
stereo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en">
<head>
<title>Polytopes and Coxeter Groups</title>
<link rel='stylesheet' href='style.css' type='text/css' />
<link rel='stylesheet' href='datgui.css' type='text/css' />
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
</head>
<body>
<script src="js/three.min.js" type="text/javascript"></script>
<script src="js/OrbitControls.js" type="text/javascript"></script>
<script src="js/Detector.js" type="text/javascript"></script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.4/svg.js" integrity="sha256-Vfh4R0uOWH2tv2NrGrtTZUo+hRBMGtEczBeTz3CSvj4="
crossorigin="anonymous"></script>
<script src="toddcoxeter.js" type="text/javascript"></script>
<script src="utils.js" type="text/javascript"></script>
<script src="js/dat.gui.min.js" type="text/javascript"></script>
<script>
var showSceneObjects;
</script>
<div class="header">
<h1>Building four dimensional polytopes</h1>
<div class="author">by Mikael Hvidtfeldt Christensen, <a href="https://twitter.com/syntopiadk?lang=en">@SyntopiaDK</a></div>
<p>Several years ago I became aware of which is called the <i>convex regular 4-polytopes</i> - basically four-dimensional analogs of the Platonic solids.
At that time I did not fully understand the mathematics, but wanted to revisit the topic at a later time.
</p>
</div>
<div class="mainContent" id="main">
<div id="rboxSimple">
</div>
<script>
function sceneAdd(scene, object, group) {
if (scene.groupings == undefined) {
scene.groupings = new Map();
}
if (scene.groupings.get(group) == undefined) {
scene.groupings.set(group, []);
}
scene.groupings.get(group).push(object);
scene.add(object);
}
function project(v) {
// Top is (0,Math.sqrt(3),0) - find line to plane a y=-Math.sqrt(3).
var dist = ( Math.sqrt(3)-v.y)/(2.0*Math.sqrt(3.0));
return new THREE.Vector3(v.x/dist,-Math.sqrt(3), v.z/dist);
}
var addProjection;
var gui = new dat.GUI({ autoPlace: false });
var staticContainer = document.getElementById("rboxSimple");
//staticContainer.style.width = "300px";
staticContainer.appendChild(gui.domElement);
var containerZ = document.createElement('div');
containerZ.style.display = "inline";
document.getElementById("main").appendChild(containerZ);
var f = gui.addFolder("Rotation");
f.open();
var pp = {
rX: 0,
rY: 0,
rZ: 0,
};
f.add(pp, "rX", 0, 6.14).name("Rotate X").onChange(function (v) {
addProjection();
});
f.add(pp, "rY", 0, 6.14).name("Rotate Y").onChange(function (v) {
addProjection();
});
f.add(pp, "rZ", 0, 6.14).name("Rotate Z").onChange(function (v) {
addProjection();
});
init();
function init() {
var d = document.getElementById("rboxSimple");
var scene = getStandard3DView(d, 500,500);
var v = getVertices();
var e = getEdges();
/*
scene.add(createPlane(v[0], v[1], v[3], 0xff0000)); // top
scene.add(createPlane(v[5], v[6], v[4], 0xff0000)); // bottom
scene.add(createPlane(v[3], v[2], v[7], 0x00ff00)); // right
scene.add(createPlane(v[0], v[1], v[4], 0x00ff00)); // left
scene.add(createPlane(v[0], v[3], v[4], 0x0000ff)); // front
scene.add(createPlane(v[1], v[2], v[5], 0x0000ff)); // back
*/
var m = new THREE.MeshStandardMaterial({
opacity: 0.3,
transparent: true,
color: 0x997744,
});
var geometry = new THREE.SphereGeometry(Math.sqrt(3), 32, 32);
var sphere = new THREE.Mesh(geometry, m);
//sphere.position.copy(v[i]);
scene.add(sphere);
var geometry = new THREE.TorusGeometry( Math.sqrt(3), 0.01, 16, 100 );
var rotObjectMatrix = new THREE.Matrix4();
rotObjectMatrix.makeRotationAxis(new THREE.Vector3(1,0,0), Math.PI/2.0);
var material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
var torus = new THREE.Mesh( geometry, material );
torus.matrix.multiply(rotObjectMatrix);
torus.rotation.setFromRotationMatrix(torus.matrix);
var geometry = new THREE.PlaneGeometry(20, 20, 32 );
var material = new THREE.MeshBasicMaterial( {color: 0xeeeeee, side: THREE.DoubleSide} );
var plane = new THREE.Mesh( geometry, material );
plane.position.copy(new THREE.Vector3(0,-Math.sqrt(3)-0.01,0));
plane.matrix.multiply(rotObjectMatrix);
plane.rotation.setFromRotationMatrix(torus.matrix);
scene.add( plane );
scene.add( torus );
scene.groupings = new Map();
scene.groupings["dynamic"] = [];
addProjection = function() {
if (scene.groupings.get("dynamic")!==undefined) {
scene.groupings.get("dynamic").forEach(function (obj) { scene.remove(obj);obj.geometry.dispose();obj.material.dispose(); });
var a = scene.groupings.get("dynamic");
while(a.length > 0) {
a.pop();
}
}
var euler = new THREE.Euler( pp.rX,pp.rY,pp.rZ );
var vv = [];
for (var i = 0; i < v.length; i++) {
vv.push(v[i].clone().applyEuler(euler));
}
var ee = [];
for (var i = 0; i < e.length; i++) {
ee.push(e[i].clone().applyEuler(euler));
}
var zenith = new THREE.Vector3(0,Math.sqrt(3),0);
spheres = [];
for (var i = 0; i < vv.length; i++) {
sceneAdd(scene,createLine(zenith,project(vv[i]), 0.0152, 0xaa0000), "dynamic");
}
var divs = 20;
for (var i = 0; i < ee.length; i+=2) {
sceneAdd(scene,createLine(ee[i],ee[i+1], 0.02, 0x444444), "dynamic");
var delta = ee[i+1].clone().sub(ee[i]).multiplyScalar(1.0/divs);
var f1 = ee[i].clone();
var f2 = f1.clone().add(delta);
for (var j = 0; j < divs; j++) {
var g1 = f1.clone().normalize().multiplyScalar(Math.sqrt(3));
var g2 = f2.clone().normalize().multiplyScalar(Math.sqrt(3));
sceneAdd(scene,createLine(project(g1),project(g2), 0.0252, 0x444444), "dynamic");
var t = f1;
f1 = f2;
f2 = t.add(delta).add(delta);
}
}
console.log(scene.children.length);
scene.doRender();
}
addProjection();
}
</script>
<div class="rightBox" id="rboxSimple2">
</div>
</div>
</body>
</html>