calabiYau = function(n, a) {
function coordinate(x, y, n, k1, k2, a) {
const z1 = math.multiply(
math.exp(math.complex(0, 2*math.PI*k1/n)),
math.pow(math.cos(math.complex(x, y)), 2/n)
);
const z2 = math.multiply(
math.exp(math.complex(0, 2*math.PI*k2/n)),
math.pow(math.sin(math.complex(x, y)), 2/n)
);
return new THREE.Vector3(z1.re, z2.re, z1.im*math.cos(a) + z2.im*math.sin(a));
}
const dx = math.PI/10;
const dy = math.PI/10;
const meshes = [];
d3.cross(d3.range(n), d3.range(n)).forEach(k => {
d3.range(0, math.PI/2, dx).forEach(x => {
d3.range(-math.PI/2, math.PI/2, dy).forEach(y => {
const data = [
{"x": x, "y": y },
{"x": x+dx, "y": y },
{"x": x+dx, "y": y+dy},
{"x": x, "y": y+dy},
];
meshes.push(normalRect(
...data.map(d => coordinate(d.x, d.y, n, k[0], k[1], a))
));
});
});
});
return meshes;
};