Graph

The graph() function creates a 2D graph of a mathematical function. The callback function should take a single argument (the x-coordinate) and return the corresponding y-coordinate.

zoom(20);

graph((x) => Math.sin(x));

You can specify a range for the x-values:

graph((x) => Math.sin(x), [-10, 10]);

Returns the Graph object:


Graph

Example usage:
graph.linewidth(2).dashed();
field
linestrip: LineStrip
The underlying LineStrip mesh representing the graph.
Example
graph.linestrip.linewidth(2);
field
values: THREE.Vector2[]
The computed (x, y) values of the graph.
Example
graph.values.map(({ x, y }) => x + y);
method
pos(position: Vec3): Graph
Set the position of the object.
param position
A vector-like object representing the position.
Example
graph.pos([1, 2, 3]);
method
color(color: GraphColor): Graph
Sets the color of the graph's line strip.
param color
A color or a function that returns a color based on x and y values, where y is the calculated graph value at x.
Example
graph.color((x, y) => (y > 0 ? "red" : "blue"));
method
material(material: LineMaterial): Graph
Sets the material of the graph's line strip.
param material
The LineMaterial to apply to the line strip.
Example
graph.material(new LineMaterial());
method
linewidth(width: number): Graph
Sets the line width of the graph's line strip.
param width
The new line width.
Example
graph.linewidth(2);
method
dashed(dashSize?: number, gapSize?: number): Graph
Sets the graph's line strip to be dashed. If no parameters are provided, default values are used.
param dashSize
Size of the dashes.
param gapSize
Size of the gaps between dashes.
Example
graph.dashed(2, 1);