Thingiverse
Passing formulas to OpenSCAD modules/functions by arpruss
by Thingiverse
Last crawled date: 3 years, 1 month ago
This page is mainly for reference. Most users will want this simpler solution which parses strings containing OpenSCAD formulas: http://www.thingiverse.com/thing:2295309
One of the features that OpenSCAD is lacking is the ability to pass functions to modules or to functions. This is a quick-and-dirty proof-of-concept solution to the not uncommon problem of wanting to pass a mathematical formula to a module or function: an eval() function that evaluates expressions in a simple LISP-inspired language that supports all of the OpenSCAD mathematical operators. The evaluation is moderately fast: about 10,000 evaluations of the sample formula below per second on my laptop. The downside is that it's pretty inconvenient to write expressions in this language.
Call the function with: eval(expression, variables). Here, variables is a table of variable values, where each line of the table has the name of the variable followed by its value, e.g., [["x", 12.3], ["y", 7]].
An expression is one the following:
a string naming a variable and expressing the value of that variable
a vector of the form ["'", value] expressing the given literal value (e.g., ["'", [12,3]] expresses the vector [12,3])
for convenience, a number expressing itself (e.g., 12.3)
a vector of the form [operator argument1 argument2 ...]
For instance, the OpenSCAD formula 3*(x*pow(y,3)-pow(x,3)*y) is expressed with ["*", 3, [ "-", ["*", "x", ["^", "y", 3]], ["*", ["^", "x", 3], "y"] ]].
The operators supported are:
The binary operations +, -, *, /, %, <, <=, >, >=, ==, !=, &&, || and the unary - and ! with the same meanings as in OpenSCAD
The binary power operator ^ or pow with the same meaning as OpenSCAD's pow(x,y)
The unary degree-based trigonometric operators cos, sin, tan, acos, asin and atan and the binary atan2 with the same meaning as in OpenSCAD
The radian-based versions COS, SIN, TAN, ACOS, ASIN, ATAN and ATAN2
The functions abs, ceil, cross, exp, floor, ln, len, log, max, min, norm, rands, round and sign with the same meanings as in OpenSCAD
The ternary operator ?, where ["?", argument1, argument2, argument3] works like OpenSCAD's argument1 ? argument2 : argument3
The binary operator # that retrieves an element from a vector: ["#", argument1, argument2] works like OpenSCAD's argument1[argument2]
The variadic operator [ that forms a vector from its arguments. E.g., ["[", 3, 4, "x"] yields the vector [3,4,x]
The unary or variadic operators max and min; when given a single argument, that argument is assumed to be a vector to calculate the maximum or minimum of; when given multiple arguments, we get the maximum or minimum of all the arguments
The variadic operator concat which concatenates all of its arguments
The binary or ternary operator range which corresponds to OpenSCAD [argument1:argument2] or [argument1:argument2:argument3]
The ternary operator gen which provides a generator expression. Do ["gen", variable, range, subexpression] to generate a vector obtained by iterating subexpression over range while varying the value of the variable indicated (variable is an expression that should evaluate to a string). (UNTESTED)
The ternary operator let: ["let", variableName, value, expression] which evaluates expression under the added assumption that variableName is a string naming a variable whose value is value; e.g., ["let", ["'", "x", 3], ["+", "x", 1]] assigns 3 to the variable named "x", and then calculates x+1
Currently, unknown operators return the operator itself, but this behavior cannot be counted on.
The OpenSCAD file contains a demo which draws Borromean rings or a (primitive) 3D function plot.
Update:
The variable system has been overhauled. The let operator has been explained.
The variable system has been overhauled again: the dollar sign operator has been removed.
One of the features that OpenSCAD is lacking is the ability to pass functions to modules or to functions. This is a quick-and-dirty proof-of-concept solution to the not uncommon problem of wanting to pass a mathematical formula to a module or function: an eval() function that evaluates expressions in a simple LISP-inspired language that supports all of the OpenSCAD mathematical operators. The evaluation is moderately fast: about 10,000 evaluations of the sample formula below per second on my laptop. The downside is that it's pretty inconvenient to write expressions in this language.
Call the function with: eval(expression, variables). Here, variables is a table of variable values, where each line of the table has the name of the variable followed by its value, e.g., [["x", 12.3], ["y", 7]].
An expression is one the following:
a string naming a variable and expressing the value of that variable
a vector of the form ["'", value] expressing the given literal value (e.g., ["'", [12,3]] expresses the vector [12,3])
for convenience, a number expressing itself (e.g., 12.3)
a vector of the form [operator argument1 argument2 ...]
For instance, the OpenSCAD formula 3*(x*pow(y,3)-pow(x,3)*y) is expressed with ["*", 3, [ "-", ["*", "x", ["^", "y", 3]], ["*", ["^", "x", 3], "y"] ]].
The operators supported are:
The binary operations +, -, *, /, %, <, <=, >, >=, ==, !=, &&, || and the unary - and ! with the same meanings as in OpenSCAD
The binary power operator ^ or pow with the same meaning as OpenSCAD's pow(x,y)
The unary degree-based trigonometric operators cos, sin, tan, acos, asin and atan and the binary atan2 with the same meaning as in OpenSCAD
The radian-based versions COS, SIN, TAN, ACOS, ASIN, ATAN and ATAN2
The functions abs, ceil, cross, exp, floor, ln, len, log, max, min, norm, rands, round and sign with the same meanings as in OpenSCAD
The ternary operator ?, where ["?", argument1, argument2, argument3] works like OpenSCAD's argument1 ? argument2 : argument3
The binary operator # that retrieves an element from a vector: ["#", argument1, argument2] works like OpenSCAD's argument1[argument2]
The variadic operator [ that forms a vector from its arguments. E.g., ["[", 3, 4, "x"] yields the vector [3,4,x]
The unary or variadic operators max and min; when given a single argument, that argument is assumed to be a vector to calculate the maximum or minimum of; when given multiple arguments, we get the maximum or minimum of all the arguments
The variadic operator concat which concatenates all of its arguments
The binary or ternary operator range which corresponds to OpenSCAD [argument1:argument2] or [argument1:argument2:argument3]
The ternary operator gen which provides a generator expression. Do ["gen", variable, range, subexpression] to generate a vector obtained by iterating subexpression over range while varying the value of the variable indicated (variable is an expression that should evaluate to a string). (UNTESTED)
The ternary operator let: ["let", variableName, value, expression] which evaluates expression under the added assumption that variableName is a string naming a variable whose value is value; e.g., ["let", ["'", "x", 3], ["+", "x", 1]] assigns 3 to the variable named "x", and then calculates x+1
Currently, unknown operators return the operator itself, but this behavior cannot be counted on.
The OpenSCAD file contains a demo which draws Borromean rings or a (primitive) 3D function plot.
Update:
The variable system has been overhauled. The let operator has been explained.
The variable system has been overhauled again: the dollar sign operator has been removed.
Similar models
thingiverse
free
Function parser for OpenSCAD and parametric curve grapher by arpruss
...dule; i also removed a warning when optimizing a function that uses norm()
may 18, 2017: pi supported
apr 17, 2019: bugfix for []
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
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;
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
Rotational Binary Print Module by avrgeek
...ows for the publishing of a binary string in a circle. heavily influenced by "rotational openscad bitmap fonts module"
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.
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
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().
thingiverse
free
Vector library for OpenScad by obijuan
...//github.com/obijuan/obiscad/
more information (in spanish) in this page:
http://www.iearobotics.com/wiki/index.php?title=obiscad
thingiverse
free
Function Grapher by JustinSDK
... [x, y, f(x, y)]
]
];
function_grapher(points, thickness);
for more information, please take a look at dotscad.
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.
Formulas
3ddd
$1
FORMULA
...formula
3ddd
кресло , новый стиль
новый стиль - formula steel chrome
3d_ocean
$30
Formula F1
...ic f1 formula indianapolis indy luxury muscle race racer sedan sports street transport tuner vehicle
generic formula f1 race car.
turbosquid
$15
Fictional Formula
...
royalty free 3d model fictional formula for download as c4d on turbosquid: 3d models for games, architecture, videos. (1447537)
3d_export
$8
formula 1
...formula 1
3dexport
3d_export
$25
Formulae 3D Model
...formulae 3d model
3dexport
racing car
formulae 3d model renexito10 70729 3dexport
turbosquid
$200
Formula Renault
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
turbosquid
$39
Formula 1
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
turbosquid
$30
Formula Cars
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
turbosquid
$15
Formula 40
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
turbosquid
$10
Formula F1
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
Passing
design_connected
free
Passe-Passe Coat Rack
...passe-passe coat rack
designconnected
free 3d model of passe-passe coat rack by ligne roset designed by nigro, philippe.
turbosquid
$5
No passing
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
3ddd
$1
Lapalma pass
...a pass
3ddd
pass , lapalma
стул lapalma pass. материалы vray. в архиве max2010, fbx, obj
turbosquid
$59
Pass Case
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
turbosquid
$5
Pass Right
... available on turbo squid, the world's leading provider of digital 3d models for visualization, films, television, and games.
3ddd
free
Passe-Partout
...няя часть спинки: клееная фанера (светлый дуб или венге)
подлокотники: полипропилен
база: матовый алюминий
текстуры в архиве.
3d_ocean
$8
Chair Lapalma pass
...3d chair furniture lapalma materials model pass stool textures vray
chair lapalma pass 3d model materials vray, textures included
3d_ocean
$1
Rocky Pass
...be also used to texture dead space rocks. the texture is perfectly planned out to support tiling and is also totally seemless....
turbosquid
$33
No Passing Sign European
...el no passing sign european for download as 3ds, max, and obj on turbosquid: 3d models for games, architecture, videos. (1303414)
3ddd
$1
Passe - Partout 2
...passe - partout 2
3ddd
сутл
офисное кресло
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.
Modules
turbosquid
$4
Module
...
turbosquid
royalty free 3d model module for download as max on turbosquid: 3d models for games, architecture, videos. (1259603)
3d_export
free
Martian module
...martian module
3dexport
martian module objects 18 textures are missing
design_connected
$39
Kennedee Moduls
...kennedee moduls
designconnected
kennedee moduls computer generated 3d model. designed by massaud, jean-marie.
design_connected
$39
Sayonara Moduls
...sayonara moduls
designconnected
bbb emmebonacina sayonara moduls computer generated 3d model. designed by decursu, giorgio.
design_connected
$27
Togo Moduls
...togo moduls
designconnected
ligne roset togo moduls computer generated 3d model. designed by ducaroy, michel.
design_connected
$34
Nuvola Moduls
...nuvola moduls
designconnected
bonaldo nuvola moduls 2-seater computer generated 3d model. designed by giuseppe viganò.
3d_export
free
Hibernation module
...hibernation module
3dexport
design_connected
$27
Sabi moduls
...sabi moduls
designconnected
paola lenti sabi moduls 2-seater computer generated 3d model. designed by francesco rota.
3d_export
$50
pls concrete module
...pls concrete module
3dexport
pls concrete module<br>pls with concrete mobile mixer module m5
turbosquid
free
Hibernation module
...squid
free 3d model hibernation module for download as blend on turbosquid: 3d models for games, architecture, videos. (1667696)
Functions
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)