Openscad quick copy of geometric objects through loops

Source: Internet
Author: User
Tags openscad

OPENSCAD supports variables and loops, allowing you to quickly replicate large numbers of geometries and lay them out in a recursive manner.

Cyclic variables can be enumerations, intervals, and vector objects, and the loop body supports geometric object construction, coordinate translation and rotation, and orthogonal.

Recursive variables for loops:

vectors (vector):

for (variable=<vector>) {<do_something>-<variable> are assigned to each successive value in the VEC Tor

Range (interval, range):

for (variable=<range>) {<do_something>}


Nested Loops : for (variable1 = <range or vector>, variable2 = <range or vector>) <do something, Using both variables>
For loops can is nested, just as in normal programs. A shorthand is so both iterations can be given in the same for statement

Usage example 1-iteration over a vector:
for (z = [-1, 1])//double iterations, z =-1, z = 1{translate ([0, 0, z]) cube (size = 1, center = false);}

Openscad iteration over a vector

Usage example 2a-iteration over a range:
for (i = [0:5]) {Rotate (i * 360/6, [1, 0, 0]) translate ([0, ten, 0]) sphere (r = 1);}

Openscad iteration over a range)

Usage example 2b-iteration over a range specifying an in Crement:
// note: the middle parameter in  the range designation //  (' 0.2 '  in this case)  is the  ' Increment-by '  value// Warning: Depending on the  ' increment-by '  value,  The// real end value may be smaller than the given one.for   ( i = [0 : 0.2 : 5] ) {    rotate ( i  * 360 / 6, [1, 0, 0])     translate ([0, 10, 0 
  ])     sphere (r = 1);} 
Usage example 3-iteration over a vector of vectors (rotation):
for (i = [[0, 0, 0], [ten, +], [[+], [+], []]) {rotate (i) CU Be ([+, a], center = true);}

Openscad for loop (rotation)

Usage example 4-iteration over a vector of vectors (translation):
 for (i = [ [ 0,  0,   0],           [10, 12, 10],            [20, 24, 20],            [30, 36, 30],            [20, 48, 40],           [10 ,  60, 50] ]) {    translate (i)     cube ([50, 15, 
    10], center = true);} 

Openscad for Loop (translation)

Nested Loop Example

For (Xpos=[0:3], ypos = [2,4,6])//Does twelve iterations, using each xpos with each ypos translate ([Xpos*ypos, ypos, 0]) Cube ([0.5, 0.5, 0.5]);

Intersection for Loop

Iterate over the values in a vector or range and take a intersection of the contents.

Note: intersection_for() is a work around because of a issue so cannot get the expected results using a combination of the standard an for() D intersection() statements. The reason is for() a implicit of the union() contents.

Parameters

    • <loop variable name>

    • Name of the variable to use within the for loop.

Usage example 1-loop over a range:
Intersection_for (n = [1:6]) {rotate ([0, 0, n *]) {translate ([5,0,0]) sphere (r=12); }}

Openscad Intersection for

Usage Example 2-rotation :
Intersection_for (i = [[0, 0, 0], [100, 20, 2], [+, +, +]]) {rotate (i) cube ([]; 0], center = true);}

Openscad intersection for (rotation)


Openscad quick copy of geometric objects through loops

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.