All examples By author By category About

bryik

Sin(e^x) with Meshline

I'm not sure what the best way to plot functions in Three.js/A-Frame is, so here's an attempt to plot sin(e^x) using the Meshline component.

Meshline's 'path' attribute takes a series of points and draws lines between them. So the idea here is to generate a ton of points in the form (x, f(x), 0). The last coordinate is 0 because the plot is constrained to a plane. The difference in x between consecutive points is arbitrarily set to 0.001.

This method is pretty inefficient for many functions (e.g. linear functions really only need two points) and probably fails for functions whose domains are not defined over the interval being plotted.