Set variables to a new value for a sub-tree. Multiple nested conditionals can become difficult to understand.įormatting them like multi-line indented "if/else" statements is clearer. from the start (or s'th element) to the i'th element - remember elements are zero basedįunction sumv(v, i, s = 0) = (i = s ? v : v + sumv(v, i-1, s)) Įcho("sum vec=", sumv(vec, 2, 1)) // calculates 20+30=50įormatting complex usage If the limit is hit, the function returns undef.Įxample // recursion - find the sum of the values in a vector (array) by calling itself Note: There is a built-in recursion limit to prevent an application crash. " it's possible to ensure the recursion is terminated. Some forms of tail-recursion elimination are supported. This works like the ?: operator from the family of C-like programming languages.Įxamples a=1 b=2 c= a=b ? 4 : 5 // 5Ī=1 b=2 c= a=b ? "a=b" : "a!=b" // "a!=b"Įcho( test ? TrueValue : FalseValue ) // falseĪ1 = test ? TrueValue : FalseValue // Values can be stored in variables, passed as function arguments, and returned as function results. FalseValue: the value to return when test is false.Ī value in OpenSCAD is either a Number (like 42), a Boolean (like true), a String (like "foo"), a Vector (like ), or the Undefined value (undef). See here for boolean and logical operators Do not confuse assignment '=' with equal '=' TrueValue: the value to return when test is true. OpenSCAD User Manual/Commented Example Projects 1 Dodecahedron 2 Icosahedron 3 Half-pyramid 4 Bounding Box 5 Linear Extrude extended use examples. See here for true or false state of values. Parameters test: Usually a boolean expression, but can be any value or variable. start - initial value increment or step - amount to increase the value, optional, default = 1 end - stop when next value would be past end examples: for (a =)echo(a) // 3 4 5įor (a =)Ī function that uses a test to determine which of 2 values to return. Note: For range, values are separated by colons rather than commas used in vectors. Parameters As a range (see section on range) slices.Evaluate each value in a range or vector, applying it to the following Action.įor(variable = ) - or additional parameters want to be forwarded (e.g. - unless default parameters want to be changed This module does not need to be modified, Linear Extrude extended use examples Linear Extrude with Scale as an interpolated function //Linear Extrude with Scale as an interpolated function Translate() scale() sphere(r=5) īoundingBox() scale() sphere(r=5) Linear_extrude(height = 1000, center = true, convexity = 10, twist = 0) The half-pyramid as rendered from the example.īounding Box // Rather kludgy module for determining bounding box from intersecting projections Create a half-pyramid from a single linear extrusion While a half-pyramid can be made with a 4-sided cone (using the cylinder primitive) and subtracting a cube from half of it, the shape can be easily made in one operation by a scaled linear extrude of a rectangle having the middle of one edge on the origin. With sloping sides no steeper than 45°, no removable support structure needs to be printed. ![]() Īn upside-down half-pyramid is a useful shape for 3D printing a support for an overhang protruding from a vertical wall. The Dodecahedron as rendered from the example.Īn icosahedron can be created from three orthogonal golden-ratio rectangles inside a hull() operation, where the golden ratio is φ = 5 + 1 2. call the module with a height of 4 and move down 4 call the module with a height of 1 and move up 2 make a cube, rotate it 116.565 degrees around the X axis, ![]() Intersection_for(i=) //loop i from 0 to 4, and intersect results 5.3 Linear Extrude with Twist and Scale as interpolated functionsĭodecahedron //create a dodecahedron by intersecting 6 boxes.5.2 Linear Extrude with Twist as an interpolated function.5.1 Linear Extrude with Scale as an interpolated function.
0 Comments
Leave a Reply. |