jared-hughes / DesThree

Desmos bindings for three.js
4 stars 0 forks source link

Add parametric geometries #40

Open jared-hughes opened 3 years ago

jared-hughes commented 3 years ago

The difficulty here is in taking Desmos functions as arguments to DesThree functions.

The global Calc object does expose the generated functions (to some degree). For example, in https://www.desmos.com/calculator/l0dcnucrrh (with the expression f(x)=x^2), Calc.controller.grapher.graphSketches[3].branches[0].compiled.fn(5) returns 5^2=25.

Perhaps values can be interpolated between generated segments from Calc.controller.grapher.graphSketches[3].branches[0].segments.

jared-hughes commented 3 years ago

Demonstrations: https://threejsfundamentals.org/threejs/lessons/threejs-primitives.html#Diagram-ParametricGeometry and https://threejs.org/examples/?q=parametric#webgl_geometry_extrude_splines. Not sure if the latter uses TubeGeometry.

jared-hughes commented 3 years ago

Observation: each branch of Calc.controller.grapher.graphSketches[3].branches is a different entry of the returned list, for example in functions like f(x)=[-1,1]*x, which return a list of values. Each one value is one branch. Maybe this can be treated as list of functions, so using f(x,y)=[x^2, y^2] would graph both the z=x^2 and the z=y^2 surfaces in one show command like Show(Mesh(ParametricSurface(f), PhongMaterial(RGB([255,0],[0,255],0)))) would graph the surface z=x^2 as red and the surface z=y^2 as green.

There does not appear to be any way to tell apart the function f(x)=[x^2] and the function f(x)=x^2 based only on Calc.controller.grapher.graphSketches. Need to look somewhere else for that.

Also will need to check for changes in the function. Could probably be handled directly in our graphChanged handler, but don't know if Calc.controller.grapher.graphSketches is updated immediately.