Published
Edited
Oct 14, 2019
17 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
position = (u, v) => {
return new THREE.Vector3(
Math.sin(u) * (7 + Math.cos(u/3 - 2*v) + 2 * Math.cos(u/3 + v)),
Math.cos(u) * (7 + Math.cos(u/3 - 2*v) + 2 * Math.cos(u/3 + v)),
Math.sin(u/3 - 2*v) + 2 * Math.sin(u/3 + v)
);
}
Insert cell
Insert cell
umbilicTorus = {
const meshes = [];

const du = Math.PI / 20;
const dv = Math.PI / 20;
d3.range(-Math.PI, Math.PI, du).forEach(u => {
d3.range(-Math.PI, Math.PI, dv).forEach(v => {
const param = [
{u: u, v: v },
{u: u+du, v: v },
{u: u+du, v: v+dv},
{u: u, v: v+dv}
];

meshes.push(rect(
...param.map(p => position(p.u, p.v)),
materials[material]
));
});
});

return meshes;
}
Insert cell
Insert cell
// Make a Plane mesh with specified Material
rect = (v1, v2, v3, v4, material) => {
const planeGeometry = new THREE.Geometry();
// add vertices
[v1, v2, v3, v4].forEach(v => planeGeometry.vertices.push(v));
// add faces
planeGeometry.faces.push(new THREE.Face3(0, 1, 2));
planeGeometry.faces.push(new THREE.Face3(2, 3, 0));
planeGeometry.computeFaceNormals();
// mesh
const plane = new THREE.Mesh( planeGeometry, material );
return plane;
}
Insert cell
scene = {
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x202020);
umbilicTorus.forEach(m => scene.add(m));
return scene;
}
Insert cell
camera = {
const fov = 45;
const aspect = width / height;
const near = 0.1;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(20, 10, 10)
camera.lookAt(new THREE.Vector3(0, 0, 0));
return camera;
}
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