Published
Edited
Feb 6, 2021
1 star
Insert cell
Insert cell
vZomeRenderer( redsegments, icosahedral_solid_connectors_shapes, 800, 1 )
Insert cell
reds = ([
[[-1,1],[0],[1]], [[1],[-1,1],[0]], [[0],[1],[-1,1]],
[[1,-1],[0],[1]], [[0],[-1],[-1,1]], [[1],[1,-1],[0]]
])
Insert cell
path = function path (displacements, start=[[0],[0],[0]]) {
return displacements.reduce(
(acc, v, i) => (acc.push([acc[i][1], vectoradd(acc[i][1], v)]), acc),
[[,start]]).slice(1);
}
Insert cell
red_shape = scale([3,5], flatten1(permute(reds).map(p => path(p, [[-1],[0],[,-1]]))))
Insert cell
redsegments = resolveSegments(red_shape)
Insert cell
scale = (scalar, model) => model.map(strut => strut.map(end => scalarmul(scalar, end)))
Insert cell
class IndexedSet {
constructor() {
this.contents = [];
this.map = new Map;
}
add(item) {
const itemhash = JSON.stringify(item);
let index = this.map.get(itemhash);
if (index == null) {
index = this.contents.length;
this.contents.push(item);
this.map.set(itemhash, index);
}
return index;
}
}
Insert cell
resolveSegments = {
return function resolveSegments( segments ) {
const scale = [2,3,1]; // phi cubed
const vertices = new IndexedSet, quaternions = new IndexedSet,
balls = new IndexedSet, struts = new IndexedSet, strutdata = [];

for (let segment of segments) {
const startpoint = scalarmul(scale, segment[0]);
const endpoint = scalarmul(scale, segment[1]);
const startindex = vertices.add(startpoint);
const endindex = vertices.add(endpoint);
balls.add(startindex), balls.add(endindex);
if (startindex != endindex) struts.add([startindex,endindex].sort());
}
for (let [startindex, endindex] of struts.contents) {
const startpoint = vertices.contents[startindex];
const endpoint = vertices.contents[endindex];
const displacement = vectorsub(endpoint, startpoint);
const [orbit, quaternion, reflected, length] = orbit2(displacement);
const quatindex = quaternions.add(quaternion);
strutdata.push({
orbit: JSON.stringify(orbit), orientation: quatindex,
start: reflected ? endindex : startindex, length: length });
}

return {
vertices: vertices, balls: balls,
quaternions: quaternions, struts: strutdata };
}
}
Insert cell
Insert cell
flatten1 = (arr) => [].concat(...arr)
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more