Thingiverse
Function parser for OpenSCAD and parametric curve grapher by arpruss
by Thingiverse
Last crawled date: 3 years, 1 month ago
One of the OpenSCAD limitations is the inability to pass functions to functions or modules.
This library lets you define mathematical functions in a string, using all of the OpenSCAD mathematical operators (and a bit more). This string is then compiled to an optimized representation which can be evaluated fairly quickly. For instance:
use;
f = "pow(x,3)*y-x*cos(y)+y";
fc = compileFunction(f);
echo(eval(fc, [["x", 12], ["y", -5]]));
will evaluate the function at x=12 and y=-5.
Parsing the string is not fast, but if you evaluate the compiled function for different variable values, the evaluated function should be fairly fast (in my test, about 10,000 eval()s per second).
There are three public functions provided:
compileFunction(f): takes a function string f and returns an optimized compiled representation; the representation is described here: http://www.thingiverse.com/thing:2289738
There may be some bugs in the optimization. If you run into problems, add the optional argument optimize=false.
eval(fc, variables): takes a compiled function fc and evaluates it for the specified parameter values; variables is a vector of [variableName, value] pairs; for instance, [["x",1],["y",2]]
evaluateFunction(expression, variables): use this to evaluate an uncompiled function once; this is a convenience function equivalent to eval(compileFunction(expression,optimize=false),variables); if you are going to evaluate the function more than a couple of times, please compile it once first, and then call eval() on the compiled version
The string function representations should be able to use all of the following standard OpenSCAD language elements:
+ - * / %
pow sqrt cos sin tan acos asin atan atan2 abs ceil exp floor ln log round sign
PI
cross norm max min concat
let
?: != == >= <= < > ! && ||
Vectors are supported, using [x,y,z] style vector forming and a[i] indexing.
Numbers can be specified in the usual way, and the true and false constants are available.
Additionally, the ^ infix operator is provided as a shorthand for pow, and COS, SIN, TAN, ACOS, ASIN, ATAN and ATAN2 are provided which are radian-based trigonometric functions.
There are likely multiple bugs I have yet to catch, and there may be some subtle deviations from OpenSCAD order of operations.
The demo file is a 3D parametric curve grapher. You should be able to use the Customizer (unless it times out) to change the formula.
Benchmarks:
On my i5 based Windows 10 laptop, per 10,000 runs with x^3*y-x*y^3:
compileFunction() with optimization: 25 seconds
compileFunction() without optimization: 21 seconds
eval() applied to precompiled function: 0.8 seconds
evaluateFunction() 22 seconds
Note: As I update eval.scad, I will upload new versions here. However, I will not be regularly updating the version inside the demo file. There is a repository here:https://github.com/arpruss/miscellaneous-scad
Update notes:
July 8, 2020: fixed bug in pow
June 1, 2020: added interpolate(x,vector) function to the language: vector is a list of [x,value] pairs where the value can be a vector or a scalar
May 21, 2019: update to remove warnings for OpenSCAD 2019.05; will no longer work on earlier versions (use eval-pre2019.scad)
July 19, 2018: bug fixes for let
Jan 18, 2018: evaluateFunction(x) works when x is a scalar: it just returns x
May 6, 2017: No longer distinguish the "fast" variables x,y,z,t from the others. Remove dollar sign operator for variable values in compiled form now that I've discovered a fast check for whether something is a string.
May 16, 2017: Fix evaluator bug in some functions like exp(x) and floor(x).
May 17, 2017: compileFunction() and evaluateFunction() should now work if fed in an already-compiled function; in that case, compileFunction() returns its input and evaluateFunction() is the same as eval(); this means that you can seamlessly support compiled and uncompiled function arguments in the same module; I also removed a warning when optimizing a function that uses norm()
May 18, 2017: PI supported
Apr 17, 2019: bugfix for []
This library lets you define mathematical functions in a string, using all of the OpenSCAD mathematical operators (and a bit more). This string is then compiled to an optimized representation which can be evaluated fairly quickly. For instance:
use
f = "pow(x,3)*y-x*cos(y)+y";
fc = compileFunction(f);
echo(eval(fc, [["x", 12], ["y", -5]]));
will evaluate the function at x=12 and y=-5.
Parsing the string is not fast, but if you evaluate the compiled function for different variable values, the evaluated function should be fairly fast (in my test, about 10,000 eval()s per second).
There are three public functions provided:
compileFunction(f): takes a function string f and returns an optimized compiled representation; the representation is described here: http://www.thingiverse.com/thing:2289738
There may be some bugs in the optimization. If you run into problems, add the optional argument optimize=false.
eval(fc, variables): takes a compiled function fc and evaluates it for the specified parameter values; variables is a vector of [variableName, value] pairs; for instance, [["x",1],["y",2]]
evaluateFunction(expression, variables): use this to evaluate an uncompiled function once; this is a convenience function equivalent to eval(compileFunction(expression,optimize=false),variables); if you are going to evaluate the function more than a couple of times, please compile it once first, and then call eval() on the compiled version
The string function representations should be able to use all of the following standard OpenSCAD language elements:
+ - * / %
pow sqrt cos sin tan acos asin atan atan2 abs ceil exp floor ln log round sign
PI
cross norm max min concat
let
?: != == >= <= < > ! && ||
Vectors are supported, using [x,y,z] style vector forming and a[i] indexing.
Numbers can be specified in the usual way, and the true and false constants are available.
Additionally, the ^ infix operator is provided as a shorthand for pow, and COS, SIN, TAN, ACOS, ASIN, ATAN and ATAN2 are provided which are radian-based trigonometric functions.
There are likely multiple bugs I have yet to catch, and there may be some subtle deviations from OpenSCAD order of operations.
The demo file is a 3D parametric curve grapher. You should be able to use the Customizer (unless it times out) to change the formula.
Benchmarks:
On my i5 based Windows 10 laptop, per 10,000 runs with x^3*y-x*y^3:
compileFunction() with optimization: 25 seconds
compileFunction() without optimization: 21 seconds
eval() applied to precompiled function: 0.8 seconds
evaluateFunction() 22 seconds
Note: As I update eval.scad, I will upload new versions here. However, I will not be regularly updating the version inside the demo file. There is a repository here:https://github.com/arpruss/miscellaneous-scad
Update notes:
July 8, 2020: fixed bug in pow
June 1, 2020: added interpolate(x,vector) function to the language: vector is a list of [x,value] pairs where the value can be a vector or a scalar
May 21, 2019: update to remove warnings for OpenSCAD 2019.05; will no longer work on earlier versions (use eval-pre2019.scad)
July 19, 2018: bug fixes for let
Jan 18, 2018: evaluateFunction(x) works when x is a scalar: it just returns x
May 6, 2017: No longer distinguish the "fast" variables x,y,z,t from the others. Remove dollar sign operator for variable values in compiled form now that I've discovered a fast check for whether something is a string.
May 16, 2017: Fix evaluator bug in some functions like exp(x) and floor(x).
May 17, 2017: compileFunction() and evaluateFunction() should now work if fed in an already-compiled function; in that case, compileFunction() returns its input and evaluateFunction() is the same as eval(); this means that you can seamlessly support compiled and uncompiled function arguments in the same module; I also removed a warning when optimizing a function that uses norm()
May 18, 2017: PI supported
Apr 17, 2019: bugfix for []
Similar models
thingiverse
free
Passing formulas to OpenSCAD modules/functions by arpruss
...d. the let operator has been explained.
the variable system has been overhauled again: the dollar sign operator has been removed.
thingiverse
free
Function Grapher by JustinSDK
... [x, y, f(x, y)]
]
];
function_grapher(points, thickness);
for more information, please take a look at dotscad.
thingiverse
free
String Theory, a string library for OpenSCAD by 16807
...ity is exposed where ever there is a "regex" parameter flag in a method's signature, and of course, through grep().
grabcad
free
Riemann Sum
...n here is the so-called "monkey saddle": f(x,y) = x^3 - 3xy². the stl files have been generated using an openscad file.
thingiverse
free
OpenSCAD type detector by arpruss
...d now run in o(1) time.
update: may 8, 2017: optimized typeof() by removing function calls and duplication of code between tests.
thingiverse
free
Formula: spring festival couplet by JustinSDK
... 4)) - pow(100, 16) / pow((pow(pow(x - 4, 2) + pow(y + 5, 2) - 13, 2) + pow(pow(x - 19, 2) + pow(y + 12, 2) - 400, 2)), 16) - 25;
thingiverse
free
The OpenScad Useful Library by roipoussiere
...t;01110", 2)); // 14
echo(atoi("d5a4", 16)); // 54692
echo(atoi("-5") + atoi("10") + 5); // 10
thingiverse
free
OpenSCAD ASCII to decimal number function by jesse
...ber. the atof("%size%") placeholder still allows the openscad document to pass compilation which helps with debugging.
thingiverse
free
2-D Riemann sums by osj1961
... 3xy^2. the number of divisions and the particular function shown can easily be changed in the top section of the openscad file.
grabcad
free
Solar tracker
...ompile different units used in "green technology" as a project to explain to students it's operation/functionality.
Parser
thingiverse
free
3D function plotter for Customizer / OpenSCAD by arpruss
...for a polyhedron(). this demonstrates and uses my function parser the standalone version bundles the parser. update: may 17,...
thingiverse
free
Twisty vases via customizable polar graphs by arpruss
...file uses (and bundles) my tube mesh and function parser libraries. updates: july 6-8, 2017: fix bug that cut...
thingiverse
free
ImplicitCAD shell() Examples by colah
...that, since the last examples were posted, implicitcad's extopenscad parser has gained support for openscad modules. and it supports...
thingiverse
free
WIP Lighter for Peugeot 205 by Jaguare19
...editor - awesome web-based text editor markdown-it - markdown parser done right. fast and easy to extend. twitter bootstrap...
thingiverse
free
Thing-O-Matic Accelerated Custom Firmware by ScribbleJ
...filament by only changing one number, for example. gcode parser - the firmware speaks gcode, like repraps do, not...
thingiverse
free
OpenJsCad: like OpenSCAD, but using JavaScript by joostn
...can be stored in variables. update: i've added a parser for local files as well. create your own .jscad...
thingiverse
free
Mini Laser Cutter / Engraver by PawArmy
...a arduino pro mini running grbl an open source g-code-parser and cnc milling controller. the cd-rom drive stepper motors...
thingiverse
free
fibonacci spiral pencil/match/gluegunrod/bolt/drillbit holder lamp by Zoon1234micron
...tip me, i had to write a scad code parser to send matrices from another program. (even just to...
thingiverse
free
Bezier Mesh Surface V0.7 by WilliamAAdams
...is also a nifty little thing called a segment parser it takes the endpoints for a line, and returns...
Grapher
thingiverse
free
Function Grapher by JustinSDK
... [x, y, f(x, y)]
]
];
function_grapher(points, thickness);
for more information, please take a look at dotscad.
thingiverse
free
Wind Spinner/Display Cage by pseudoeuclidean
...to my computer. go ahead... pick up your 3d grapher and punch it in! the three blades placed along...
grabcad
free
GRAFADOR DE 2 ROLDANAS - GRAPHER
...grafador de 2 roldanas - grapher
grabcad
grafadora de 2 roldanas utilizada en industria farmacéutica y de perfumería.
grabcad
free
Coupling with Parallel Axis (231)
...be verified by applying dynamic simulation - the output grapher presents the two speeds in the attached picture. the...
grabcad
free
Train along path
...parameters and to analyse the results in the output grapher ...
grabcad
free
Gear Slider
...picture stroke and velocity.jpg. the two pictures of output grapher explain all - „if you have eyes to see”,...
grabcad
free
Watt Governor in Action
...mm. if you look at the included picture "output grapher - with sabots contact.jpg" you can see how the...
grabcad
free
Spherical Levers Coupling - 3 Lever Configuration
...simply press the play button and open the output grapher ...
grabcad
free
Classic Escapement - Graham (Modified)
...degrees are awarded sparingly. included are the files „output grapher (10s).jpg” and „output grapher (60s).jpg” where you can see...
Arpruss
thingiverse
free
Watch band part by arpruss
...watch band part by arpruss
thingiverse
my son needed this.
thingiverse
free
Smiley face stencil by arpruss
...smiley face stencil by arpruss
thingiverse
simple smiley face stencil.
thingiverse
free
Folding chair foot by arpruss
...folding chair foot by arpruss
thingiverse
quick and dirty folding chair foot. customizable.
thingiverse
free
Customizable hex maze by arpruss
...customizable hex maze by arpruss
thingiverse
generates a hex-cell maze using recursive backtracking.
thingiverse
free
Customizable cable clip by arpruss
...ustomizable cable clip by arpruss
thingiverse
this is a simple customizable cable clip.
this uses and bundles my bezier library.
thingiverse
free
Customizable unicorn horn by arpruss
...ingiverse
customize twist, rounding, height, diameter and number of lobes.
uses (and bundles) my tube mesh and bezier libraries.
thingiverse
free
Wooden railway bridge support by arpruss
...wooden railway bridge support by arpruss
thingiverse
yet another support for brio-style wooden railroad bridges. customizable.
thingiverse
free
Saturn cookie cutter by arpruss
...tter was generated with inkscape and some plugins. instructions on how to do this are here. you can customize various dimensions.
thingiverse
free
Randomized leafy snowflake by arpruss
...domized snowflake generator for blockscad (with an openscad-based customizer exported from it, and variables moved to beginning).
thingiverse
free
Smiley face by arpruss
...inflation scripts. there is a positive version where the eyes and mouth stick out, and a negative version where they are cut out.
Parametric
turbosquid
$25
Parametric
...oyalty free 3d model parametric for download as blend and stl on turbosquid: 3d models for games, architecture, videos. (1683196)
3ddd
$1
Parametric Wall
...parametric wall
3ddd
панель
parametric wall with shelf
3d_export
$5
parametric table
...parametric table
3dexport
parametric table model created on rhinoceros 6. this 3d model includes: .gh, .3dm files
turbosquid
$2
Parametric Seat
...id
royalty free 3d model parametric seat for download as max on turbosquid: 3d models for games, architecture, videos. (1691557)
turbosquid
$2
Parametric Wall
...id
royalty free 3d model parametric wall for download as max on turbosquid: 3d models for games, architecture, videos. (1690373)
turbosquid
$2
parametrical chandelier
...lty free 3d model parametrical chandelier for download as dxf on turbosquid: 3d models for games, architecture, videos. (1257635)
turbosquid
$1
Parametric Wall
...id
royalty free 3d model parametric wall for download as max on turbosquid: 3d models for games, architecture, videos. (1691303)
turbosquid
$1
Parametric Wall
...id
royalty free 3d model parametric wall for download as max on turbosquid: 3d models for games, architecture, videos. (1691148)
turbosquid
$19
Parametric Bench
...ty free 3d model parametric bench for download as max and max on turbosquid: 3d models for games, architecture, videos. (1713396)
turbosquid
free
Parametric wall
...ee 3d model parametric wall for download as max, obj, and fbx on turbosquid: 3d models for games, architecture, videos. (1356869)
Openscad
thingiverse
free
OpenSCAD sphere
...openscad sphere
thingiverse
basic project for openscad.
thingiverse
free
Openscad Football by KySyth
...openscad football by kysyth
thingiverse
openscad not tested
thingiverse
free
Openscad Apple by KySyth
...openscad apple by kysyth
thingiverse
openscad apple = not tested
thingiverse
free
Plugs with openscad by benengel
...plugs with openscad by benengel
thingiverse
plugs with openscad and fontawesome
thingiverse
free
Openscad spirals by mafmuf
...openscad spirals by mafmuf
thingiverse
just fooling around with openscad.
thingiverse
free
Practice on OpenScad by ajensen906
...practice on openscad by ajensen906
thingiverse
a very crude practice on openscad
thingiverse
free
Batteries in OpenSCAD by roman_hegglin
...batteries in openscad by roman_hegglin
thingiverse
common batteries as modules for openscad.
thingiverse
free
OpenScad Propeller by KySyth
...se
trying to make a propeller with openscad = not tested
this is some of the results
added the openscad file but still need work
thingiverse
free
Openscad Cloud by Twanne
...openscad cloud by twanne
thingiverse
openscad cloud.
size can be adjusted
thingiverse
free
Geomag for OpenScad by vicnet
...geomag for openscad by vicnet
thingiverse
openscad file to design geomag things.
Curve
3d_export
free
curved sword
...curved sword
3dexport
a curved sword
3ddd
$1
CURVE
...wave oscillates rhythmically across this rug.
hand knotted from tibetan wool, curve is available from stock in a range of sizes.
3ddd
$1
SYSTEMPOOL Serie Curve
..., serie curve , раковина
systempool serie curve
3ddd
$1
DIAMANTE Curved Bench
...diamante curved bench
3ddd
diamante curved bench скамья
diamante curved bench
3ddd
$1
Enne Curve Sofa
...enne curve sofa
3ddd
enne , curve
диван enne curve, размеры -h800x920x2350mm
design_connected
$27
Curve Sofa
...curve sofa
designconnected
living divani curve sofa computer generated 3d model. designed by lissoni, piero.
3d_export
$5
curve base handle
...curve base handle
3dexport
curve base handle
3d_export
$5
simple curve handle
...simple curve handle
3dexport
simple curve handle
turbosquid
$2
Curved leaf
...urbosquid
royalty free 3d model curved leaf for download as on turbosquid: 3d models for games, architecture, videos. (1641948)
turbosquid
$2
Curved Mouse
...rbosquid
royalty free 3d model curved mouse for download as on turbosquid: 3d models for games, architecture, videos. (1314525)
Function
turbosquid
$1
functional clock
...d
royalty free 3d model functional clock for download as fbx on turbosquid: 3d models for games, architecture, videos. (1378928)
turbosquid
$5
functional door
... model functional door for download as 3ds, obj, c4d, and stl on turbosquid: 3d models for games, architecture, videos. (1483785)
3d_export
$5
multi function box
...multi function box
3dexport
it is multi function box in iges format
3ddd
$1
Fitness Equipament - Functional
...fitness equipament - functional
3ddd
треножер
fitness equipament functional, modeled from real model.
turbosquid
$19
Four function formula
...
royalty free 3d model four function formula for download as on turbosquid: 3d models for games, architecture, videos. (1154985)
turbosquid
$1
functional work table
...yalty free 3d model functional work table for download as max on turbosquid: 3d models for games, architecture, videos. (1198733)
3d_export
free
Multi-functional anaquel
...multi-functional anaquel
3dexport
https://www.dock4all.com/
turbosquid
$12
Multi-Function Knife
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
turbosquid
$9
function x black coin
...yalty free 3d model function x black coin for download as max on turbosquid: 3d models for games, architecture, videos. (1457828)
turbosquid
$8
Multi-function cylinder mechanism
...lti-function cylinder mechanism for download as ige and sldpr on turbosquid: 3d models for games, architecture, videos. (1223739)