Passing formulas to OpenSCAD modules/functions

Passing formulas to OpenSCAD modules/functions

Free STL Other
  • 11 views

This model is hosted on Cults3D. Files, images and license details belong to the original creator.

View on Cults3D ↗

Description

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: 1. a string naming a variable and expressing the value of that variable 2. a vector of the form ["'", value] expressing the given literal value (e.g., ["'", [12,3]] expresses the vector [12,3]) 3. for convenience, a number expressing itself (e.g., 12.3) 4. 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…

About this model

Passing formulas to OpenSCAD modules/functions is a free 3D model in the Other category, shared by the Cults3D community. You can download it for 3D printing and reuse it in your own projects under the terms of its original license.

File formats

  • STL — The most common mesh format for 3D printing — ready to slice and print on almost any printer.

The files for this model are hosted on Cults3D. Use the button above to open the original page and download it.

Similar models