Published
Edited
Jun 3, 2021
Importers
1 star
Insert cell
Insert cell
Insert cell
show_x3d([
create_hollow_cylinder([0, 0, 0], [0, 1, 0], 3, 5, 13, {
color: "#369"
})
])
Insert cell
function create_hollow_cylinder(o, d, r, R, l, opts = {}) {
let { show_top = true, show_bottom = true } = opts;
let container = d3.create("transform");
if (opts.id) {
container.attr("id", opts.id);
}
if (opts.class) {
container.attr("class", opts.class);
}

opts.top = false;
opts.bottom = false;
container.append(() => create_cylinder(o, d, r, l, opts));
let outer = create_cylinder(o, d, R, l, opts);
container.append(() => outer);
opts.Nu = 1;
opts.nu = 1;
let normed_d = normalize(d);
let [n, b] = normal_binormal(d);
if (show_top) {
container.append(() =>
create_surface(
function (s, t) {
let cos = s * Math.cos(t);
let sin = s * Math.sin(t);
return [
o[0] + normed_d[0] * l + cos * n[0] + sin * b[0],
o[1] + normed_d[1] * l + cos * n[1] + sin * b[1],
o[2] + normed_d[2] * l + cos * n[2] + sin * b[2]
];
},
[r, R],
[0, 2 * Math.PI],
opts
)
);
}
if (show_bottom) {
container.append(() =>
create_surface(
function (s, t) {
let cos = s * Math.cos(t);
let sin = s * Math.sin(t);
return [
o[0] + cos * n[0] + sin * b[0],
o[1] + cos * n[1] + sin * b[1],
o[2] + cos * n[2] + sin * b[2]
];
},
[r, R],
[0, 2 * Math.PI],
opts
)
);
}

let container_node = container.node();
container_node.extent = outer.extent;

return container_node;
}
Insert cell
d3 = require("d3-selection@2")
Insert cell
import { normal_binormal, normalize } from '@mcmcclur/x3dom-utilities'
Insert cell
import { create_surface } from "@mcmcclur/parametric-surfaces"
Insert cell
import { create_cylinder, show_x3d } from "@mcmcclur/x3dom-primitives"
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