Skip to content

Scientific geometry

Level sets and slices ​

scenes/level-sets-and-slices
const geometry =
  show === "levels"
    ? {
        kind: "levels",
        expression: "x^2 + y^2 + z^2",
        values: [4, 12, 25],
        resolution: [40, 40, 40],
        colours: [
          [0.9, 0.3, 0.2, 0.9],
          [0.3, 0.8, 0.4, 0.45],
          [0.4, 0.5, 1.0, 0.25],
        ],
      }
    : { kind: "slice", expression: "x^2 - y^2", axis: "z", at: 0, contours: [-20, -8, 0, 8, 20] };
plot.setGraph({ ...DOMAIN, plots: [{ name: "field", geometry }] });
plot.frameScene();

Calls

2 in the code above, in the order it makes them

plot.setGraph(graph: Graph): void

Draw a document of mathematical plots: expressions, curves, imported tables, and the labelled axis frame around them.

Replaces whatever graph was set before, and leaves uploaded geometry alone, so a generated surface can sit beside a point cloud under the same camera.

This is the expensive call: every plot in the document is regenerated and re-uploaded. Drawing one afterwards is not. A page with a slider over an expression's parameter should expect the cost of a keystroke, not the cost of a frame, which is why the examples keep their documents small.

plot.frameScene(): void

Point the camera at the middle of everything uploaded, far enough back to see it.

Call after uploading. A scene measured in grid cells or in millimetres is nowhere near where a camera starts, and without this the first thing a caller sees is an empty canvas.