Skip to content
/ BOSL Public
Revar Desmera edited this pageJun 13, 2020· 34 revisions

Library File transforms.scad

This is the file that the most commonly used transformations, distributors, and mutator are in. To use, add the following lines to the beginning of your file:

include <BOSL/constants.scad>
use <BOSL/transforms.scad>

Table of Contents

  1. Translations

  2. Rotations

  3. Scaling and Mirroring

  4. Skewing

  5. Translational Distributors

  6. Rotational Distributors

  7. Reflectional Distributors

  8. Mutators

  9. 2D Mutators

  10. Miscellaneous

  11. Deprecations


1. Translations

move()

Usage:

  • move([x], [y], [z]) ...
  • move([x,y,z]) ...

Description: Moves/translates children.

ArgumentWhat it does
xX axis translation.
yY axis translation.
zZ axis translation.

Example 1:

#sphere(d=10);
move([0,20,30]) sphere(d=10);

move() Example 1

Example 2:

#sphere(d=10);
move(y=20) sphere(d=10);

move() Example 2

Example 3:

#sphere(d=10);
move(x=-10, y=-5) sphere(d=10);

move() Example 3


xmove()

Usage:

  • xmove(x) ...

Description: Moves/translates children the given amount along the X axis.

ArgumentWhat it does
xAmount to move right along the X axis. Negative values move left.

Example:

#sphere(d=10);
xmove(20) sphere(d=10);

xmove() Example


ymove()

Usage:

  • ymove(y) ...

Description: Moves/translates children the given amount along the Y axis.

ArgumentWhat it does
yAmount to move back along the Y axis. Negative values move forward.

Example:

#sphere(d=10);
ymove(20) sphere(d=10);

ymove() Example


zmove()

Usage:

  • zmove(z) ...

Description: Moves/translates children the given amount along the Z axis.

ArgumentWhat it does
zAmount to move up along the Z axis. Negative values move down.

Example:

#sphere(d=10);
zmove(20) sphere(d=10);

zmove() Example


left()

Usage:

  • left(x) ...

Description: Moves children left (in the X- direction) by the given amount.

ArgumentWhat it does
xScalar amount to move left.

Example:

#sphere(d=10);
left(20) sphere(d=10);

left() Example


right()

Usage:

  • right(x) ...

Description: Moves children right (in the X+ direction) by the given amount.

ArgumentWhat it does
xScalar amount to move right.

Example:

#sphere(d=10);
right(20) sphere(d=10);

right() Example


fwd() / forward()

Usage:

  • fwd(y) ...
  • forward(y) ...

Description: Moves children forward (in the Y- direction) by the given amount.

ArgumentWhat it does
yScalar amount to move forward.

Example:

#sphere(d=10);
fwd(20) sphere(d=10);

fwd() / forward() Example


back()

Usage:

  • back(y) ...

Description: Moves children back (in the Y+ direction) by the given amount.

ArgumentWhat it does
yScalar amount to move back.

Example:

#sphere(d=10);
back(20) sphere(d=10);

back() Example


down()

Usage:

  • down(z) ...

Description: Moves children down (in the Z- direction) by the given amount.

ArgumentWhat it does
zScalar amount to move down.

Example:

#sphere(d=10);
down(20) sphere(d=10);

down() Example


up()

Usage:

  • up(z) ...

Description: Moves children up (in the Z+ direction) by the given amount.

ArgumentWhat it does
zScalar amount to move up.

Example:

#sphere(d=10);
up(20) sphere(d=10);

up() Example


2. Rotations

rot()

Usage:

  • rot(a, [cp], [reverse]) ...
  • rot([X,Y,Z], [cp], [reverse]) ...
  • rot(a, v, [cp], [reverse]) ...
  • rot(from, to, [a], [reverse]) ...

Description: Rotates children around an arbitrary axis by the given number of degrees. Can be used as a drop-in replacement for rotate(), with extra features.

ArgumentWhat it does
aScalar angle or vector of XYZ rotation angles to rotate by, in degrees.
vvector for the axis of rotation. Default: [0,0,1] or V_UP
cpcenterpoint to rotate around. Default: [0,0,0]
fromStarting vector for vector-based rotations.
toTarget vector for vector-based rotations.
reverseIf true, exactly reverses the rotation, including axis rotation ordering. Default: false

Example 1:

#cube([2,4,9]);
rot([30,60,0], cp=[0,0,9]) cube([2,4,9]);

rot() Example 1

Example 2:

#cube([2,4,9]);
rot(30, v=[1,1,0], cp=[0,0,9]) cube([2,4,9]);

rot() Example 2

Example 3:

#cube([2,4,9]);
rot(from=V_UP, to=V_LEFT+V_BACK) cube([2,4,9]);

rot() Example 3


xrot()

Usage:

  • xrot(a, [cp]) ...

Description: Rotates children around the X axis by the given number of degrees.

ArgumentWhat it does
aangle to rotate by in degrees.
cpcenterpoint to rotate around. Default: [0,0,0]

Example:

#cylinder(h=50, r=10, center=true);
xrot(90) cylinder(h=50, r=10, center=true);

xrot() Example


yrot()

Usage:

  • yrot(a, [cp]) ...

Description: Rotates children around the Y axis by the given number of degrees.

ArgumentWhat it does
aangle to rotate by in degrees.
cpcenterpoint to rotate around. Default: [0,0,0]

Example:

#cylinder(h=50, r=10, center=true);
yrot(90) cylinder(h=50, r=10, center=true);

yrot() Example


zrot()

Usage:

  • zrot(a, [cp]) ...

Description: Rotates children around the Z axis by the given number of degrees.

ArgumentWhat it does
aangle to rotate by in degrees.
cpcenterpoint to rotate around. Default: [0,0,0]

Example:

#cube(size=[60,20,40], center=true);
zrot(90) cube(size=[60,20,40], center=true);

zrot() Example


3. Scaling and Mirroring

xscale()

Usage:

  • xscale(x) ...

Description: Scales children by the given factor on the X axis.

ArgumentWhat it does
xFactor to scale by along the X axis.

Example:

xscale(3) sphere(r=10);

xscale() Example


yscale()

Usage:

  • yscale(y) ...

Description: Scales children by the given factor on the Y axis.

ArgumentWhat it does
yFactor to scale by along the Y axis.

Example:

yscale(3) sphere(r=10);

yscale() Example


zscale()

Usage:

  • zscale(z) ...

Description: Scales children by the given factor on the Z axis.

ArgumentWhat it does
zFactor to scale by along the Z axis.

Example:

zscale(3) sphere(r=10);

zscale() Example


xflip()

Usage:

  • xflip([cp]) ...

Description: Mirrors the children along the X axis, like mirror([1,0,0]) or xscale(-1)

ArgumentWhat it does
cpA point that lies on the plane of reflection.

Example 1:

xflip() yrot(90) cylinder(d1=10, d2=0, h=20);
color("blue", 0.25) cube([0.01,15,15], center=true);
color("red", 0.333) yrot(90) cylinder(d1=10, d2=0, h=20);

xflip() Example 1

Example 2:

xflip(cp=[-5,0,0]) yrot(90) cylinder(d1=10, d2=0, h=20);
color("blue", 0.25) left(5) cube([0.01,15,15], center=true);
color("red", 0.333) yrot(90) cylinder(d1=10, d2=0, h=20);

xflip() Example 2


yflip()

Usage:

  • yflip([cp]) ...

Description: Mirrors the children along the Y axis, like mirror([0,1,0]) or yscale(-1)

ArgumentWhat it does
cpA point that lies on the plane of reflection.

Example 1:

yflip() xrot(90) cylinder(d1=10, d2=0, h=20);
color("blue", 0.25) cube([15,0.01,15], center=true);
color("red", 0.333) xrot(90) cylinder(d1=10, d2=0, h=20);

yflip() Example 1

Example 2:

yflip(cp=[0,5,0]) xrot(90) cylinder(d1=10, d2=0, h=20);
color("blue", 0.25) back(5) cube([15,0.01,15], center=true);
color("red", 0.333) xrot(90) cylinder(d1=10, d2=0, h=20);

yflip() Example 2


zflip()

Usage:

  • zflip([cp]) ...

Description: Mirrors the children along the Z axis, like mirror([0,0,1]) or zscale(-1)

ArgumentWhat it does
cpA point that lies on the plane of reflection.

Example 1:

zflip() cylinder(d1=10, d2=0, h=20);
color("blue", 0.25) cube([15,15,0.01], center=true);
color("red", 0.333) cylinder(d1=10, d2=0, h=20);

zflip() Example 1

Example 2:

zflip(cp=[0,0,-5]) cylinder(d1=10, d2=0, h=20);
color("blue", 0.25) down(5) cube([15,15,0.01], center=true);
color("red", 0.333) cylinder(d1=10, d2=0, h=20);

zflip() Example 2


4. Skewing

skew_xy() / skew_z()

Usage:

  • skew_xy([xa], [ya]) ...
  • skew_z([xa], [ya]) ...

Description: Skews children on the X-Y plane, keeping constant in Z.

ArgumentWhat it does
xaskew angle towards the X direction.
yaskew angle towards the Y direction.
planarIf true, this becomes a 2D operation.

Example 1:

#cube(size=10);
skew_xy(xa=30, ya=15) cube(size=10);

skew_xy() / skew_z() Example 1

Example 2:

skew_xy(xa=15,ya=30,planar=true) square(30);

skew_xy() / skew_z() Example 2


skew_yz() / skew_x()

Usage:

  • skew_yz([ya], [za]) ...
  • skew_x([ya], [za]) ...

Description: Skews children on the Y-Z plane, keeping constant in X.

ArgumentWhat it does
yaskew angle towards the Y direction.
zaskew angle towards the Z direction.

Example:

#cube(size=10);
skew_yz(ya=30, za=15) cube(size=10);

skew_yz() / skew_x() Example


skew_xz() / skew_y()

Usage:

  • skew_xz([xa], [za]) ...
  • skew_y([xa], [za]) ...

Description: Skews children on the X-Z plane, keeping constant in Y.

ArgumentWhat it does
xaskew angle towards the X direction.
zaskew angle towards the Z direction.

Example:

#cube(size=10);
skew_xz(xa=15, za=-10) cube(size=10);

skew_xz() / skew_y() Example


5. Translational Distributors

place_copies()

Usage:

  • place_copies(a) ...

Description: Makes copies of the given children at each of the given offsets.

ArgumentWhat it does
aarray of XYZ offset vectors. Default 0,0,0

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.

Example:

#sphere(r=10);
place_copies([[-25,-25,0], [25,-25,0], [0,0,50], [0,25,0]]) sphere(r=10);

place_copies() Example


spread()

Usage:

  • spread(l, [n], [p1]) ...
  • spread(l, spacing, [p1]) ...
  • spread(spacing, [n], [p1]) ...
  • spread(p1, p2, [n]) ...
  • spread(p1, p2, spacing) ...

Description: Evenly distributes n copies of all children along a line. Copies every child at each position.

ArgumentWhat it does
p1Starting point of line.
p2Ending point of line.
lLength to spread copies over.
spacingA 3D vector indicating which direction and distance to place each subsequent copy at.
nNumber of copies to distribute along the line. (Default: 2)

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
  • $idx is set to the index number of each child being copied.

Example 1:

spread([0,0,0], [5,5,20], n=6) cube(size=[3,2,1],center=true);

spread() Example 1

Example 2:

spread(l=40, n=6) cube(size=[3,2,1],center=true);

spread() Example 2

Example 3:

spread(l=[15,30], n=6) cube(size=[3,2,1],center=true);

spread() Example 3

Example 4:

spread(l=40, spacing=10) cube(size=[3,2,1],center=true);

spread() Example 4

Example 5:

spread(spacing=[5,5,0], n=5) cube(size=[3,2,1],center=true);

spread() Example 5

Example 6:

spread(l=20, n=3) {
    cube(size=[1,3,1],center=true);
    cube(size=[3,1,1],center=true);
}

spread() Example 6


xspread()

Usage:

  • xspread(spacing, [n], [sp]) ...
  • xspread(l, [n], [sp]) ...

Description: Spreads out n copies of the children along a line on the X axis.

ArgumentWhat it does
spacingspacing between copies. (Default: 1.0)
nNumber of copies to spread out. (Default: 2)
lLength to spread copies over.
spIf given, copies will be spread on a line to the right of starting position sp. If not given, copies will be spread along a line that is centered at [0,0,0].

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
  • $idx is set to the index number of each child being copied.

Example 1:

xspread(20) sphere(3);

xspread() Example 1

Example 2:

xspread(20, n=3) sphere(3);

xspread() Example 2

Example 3:

xspread(spacing=15, l=50) sphere(3);

xspread() Example 3

Example 4:

xspread(n=4, l=30, sp=[0,10,0]) sphere(3);

xspread() Example 4

Example 5:

xspread(10, n=3) {
    cube(size=[1,3,1],center=true);
    cube(size=[3,1,1],center=true);
}

xspread() Example 5


yspread()

Usage:

  • yspread(spacing, [n], [sp]) ...
  • yspread(l, [n], [sp]) ...

Description: Spreads out n copies of the children along a line on the Y axis.

ArgumentWhat it does
spacingspacing between copies. (Default: 1.0)
nNumber of copies to spread out. (Default: 2)
lLength to spread copies over.
spIf given, copies will be spread on a line back from starting position sp. If not given, copies will be spread along a line that is centered at [0,0,0].

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
  • $idx is set to the index number of each child being copied.

Example 1:

yspread(20) sphere(3);

yspread() Example 1

Example 2:

yspread(20, n=3) sphere(3);

yspread() Example 2

Example 3:

yspread(spacing=15, l=50) sphere(3);

yspread() Example 3

Example 4:

yspread(n=4, l=30, sp=[10,0,0]) sphere(3);

yspread() Example 4

Example 5:

yspread(10, n=3) {
    cube(size=[1,3,1],center=true);
    cube(size=[3,1,1],center=true);
}

yspread() Example 5


zspread()

Usage:

  • zspread(spacing, [n], [sp]) ...
  • zspread(l, [n], [sp]) ...

Description: Spreads out n copies of the children along a line on the Z axis.

ArgumentWhat it does
spacingspacing between copies. (Default: 1.0)
nNumber of copies to spread out. (Default: 2)
lLength to spread copies over.
spIf given, copies will be spread on a line up from starting position sp. If not given, copies will be spread along a line that is centered at [0,0,0].

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
  • $idx is set to the index number of each child being copied.

Example 1:

zspread(20) sphere(3);

zspread() Example 1

Example 2:

zspread(20, n=3) sphere(3);

zspread() Example 2

Example 3:

zspread(spacing=15, l=50) sphere(3);

zspread() Example 3

Example 4:

zspread(n=4, l=30, sp=[10,0,0]) sphere(3);

zspread() Example 4

Example 5:

zspread(10, n=3) {
    cube(size=[1,3,1],center=true);
    cube(size=[3,1,1],center=true);
}

zspread() Example 5


distribute()

Usage:

  • distribute(spacing, dir, [sizes]) ...
  • distribute(l, dir, [sizes]) ...

Description: Spreads out each individual child along the direction dir. Every child is placed at a different position, in order. This is useful for laying out groups of disparate objects where you only really care about the spacing between them.

ArgumentWhat it does
spacingSpacing to add between each child. (Default: 10.0)
sizesArray containing how much space each child will need.
dirVector direction to distribute copies along.
lLength to distribute copies along.

Example:

distribute(sizes=[100, 30, 50], dir=V_UP) {
    sphere(r=50);
    cube([10,20,30], center=true);
    cylinder(d=30, h=50, center=true);
}

distribute() Example


xdistribute()

Usage:

  • xdistribute(spacing, [sizes]) ...
  • xdistribute(l, [sizes]) ...

Description: Spreads out each individual child along the X axis. Every child is placed at a different position, in order. This is useful for laying out groups of disparate objects where you only really care about the spacing between them.

ArgumentWhat it does
spacingspacing between each child. (Default: 10.0)
sizesArray containing how much space each child will need.
lLength to distribute copies along.

Example:

xdistribute(sizes=[100, 10, 30], spacing=40) {
    sphere(r=50);
    cube([10,20,30], center=true);
    cylinder(d=30, h=50, center=true);
}

xdistribute() Example


ydistribute()

Usage:

  • ydistribute(spacing, [sizes])
  • ydistribute(l, [sizes])

Description: Spreads out each individual child along the Y axis. Every child is placed at a different position, in order. This is useful for laying out groups of disparate objects where you only really care about the spacing between them.

ArgumentWhat it does
spacingspacing between each child. (Default: 10.0)
sizesArray containing how much space each child will need.
lLength to distribute copies along.

Example:

ydistribute(sizes=[30, 20, 100], spacing=40) {
    cylinder(d=30, h=50, center=true);
    cube([10,20,30], center=true);
    sphere(r=50);
}

ydistribute() Example


zdistribute()

Usage:

  • zdistribute(spacing, [sizes])
  • zdistribute(l, [sizes])

Description: Spreads out each individual child along the Z axis. Every child is placed at a different position, in order. This is useful for laying out groups of disparate objects where you only really care about the spacing between them.

ArgumentWhat it does
spacingspacing between each child. (Default: 10.0)
sizesArray containing how much space each child will need.
lLength to distribute copies along.

Example:

zdistribute(sizes=[30, 20, 100], spacing=40) {
    cylinder(d=30, h=50, center=true);
    cube([10,20,30], center=true);
    sphere(r=50);
}

zdistribute() Example


grid2d()

Usage:

  • grid2d(size, spacing, [stagger], [scale], [in_poly], [orient], [align]) ...
  • grid2d(size, cols, rows, [stagger], [scale], [in_poly], [orient], [align]) ...
  • grid2d(spacing, cols, rows, [stagger], [scale], [in_poly], [orient], [align]) ...
  • grid2d(spacing, in_poly, [stagger], [scale], [orient], [align]) ...
  • grid2d(cols, rows, in_poly, [stagger], [scale], [orient], [align]) ...

Description: Makes a square or hexagonal grid of copies of children.

ArgumentWhat it does
sizeThe [X,Y] size to spread the copies over.
spacingDistance between copies in [X,Y] or scalar distance.
colsHow many columns of copies to make. If staggered, count both staggered and unstaggered columns.
rowsHow many rows of copies to make. If staggered, count both staggered and unstaggered rows.
staggerIf true, make a staggered (hexagonal) grid. If false, make square grid. If "alt", makes alternate staggered pattern. Default: false
scale[X,Y] scaling factors to reshape grid.
in_polyIf given a list of polygon points, only creates copies whose center would be inside the polygon. Polygon can be concave and/or self crossing.
orientOrientation axis for the grid. Orientation is NOT applied to individual children.
alignAlignment of the grid. Alignment is NOT applies to individual children.

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
  • $col is set to the integer column number for each child.
  • $row is set to the integer row number for each child.

Example 1:

grid2d(size=50, spacing=10, stagger=false) cylinder(d=10, h=1);

grid2d() Example 1

Example 2:

grid2d(spacing=10, rows=7, cols=13, stagger=true) cylinder(d=6, h=5);

grid2d() Example 2

Example 3:

grid2d(spacing=10, rows=7, cols=13, stagger="alt") cylinder(d=6, h=5);

grid2d() Example 3

Example 4:

grid2d(size=50, rows=11, cols=11, stagger=true) cylinder(d=5, h=1);

grid2d() Example 4

Example 5:

poly = [[-25,-25], [25,25], [-25,25], [25,-25]];
grid2d(spacing=5, stagger=true, in_poly=poly)
   zrot(180/6) cylinder(d=5, h=1, $fn=6);
%polygon(poly);

grid2d() Example 5

Example 6:

// Makes a grid of hexagon pillars whose tops are all angled
// to reflect light at [0,0,50], if they were reflective.
use <BOSL/math.scad>
hexregion = [for (a = [0:60:359.9]) 50.01*[cos(a), sin(a)]];
grid2d(spacing=10, stagger=true, in_poly=hexregion) {
    // Note: You must use for(var=[val]) or let(var=val)
    // to set vars from $pos or other special vars in this scope.
    let (ref_v = (normalize([0,0,50]-point3d($pos)) + V_UP)/2)
        half_of(v=-ref_v, cp=[0,0,5])
            zrot(180/6)
                cylinder(h=20, d=10/cos(180/6)+0.01, $fn=6);
}

grid2d() Example 6


grid3d()

Usage:

  • grid3d(n, spacing) ...
  • grid3d(n=[Xn,Yn,Zn], spacing=[dX,dY,dZ]) ...
  • grid3d([xa], [ya], [za]) ...

Description: Makes a 3D grid of duplicate children.

ArgumentWhat it does
xaarray or range of X-axis values to offset by. (Default: [0])
yaarray or range of Y-axis values to offset by. (Default: [0])
zaarray or range of Z-axis values to offset by. (Default: [0])
nOptional number of copies to have per axis.
spacingspacing of copies per axis. Use with n.

Example 1:

grid3d(xa=[0:25:50],ya=[0,40],za=[-20:40:20]) sphere(r=5);

grid3d() Example 1

Example 2:

grid3d(n=[3, 4, 2], spacing=[60, 50, 40]) sphere(r=10);

grid3d() Example 2

Example 3:

grid3d(ya=[-60:40:60],za=[0,70]) sphere(r=10);

grid3d() Example 3

Example 4:

grid3d(n=3, spacing=30) sphere(r=10);

grid3d() Example 4

Example 5:

grid3d(n=[3, 1, 2], spacing=30) sphere(r=10);

grid3d() Example 5

Example 6:

grid3d(n=[3, 4], spacing=[80, 60]) sphere(r=10);

grid3d() Example 6

Example 7:

grid3d(n=[10, 10, 10], spacing=50) color($idx/9) cube(50, center=true);

grid3d() Example 7


6. Rotational Distributors

rot_copies()

Usage:

  • rot_copies(rots, [cp], [sa], [delta], [subrot]) ...
  • rot_copies(rots, v, [cp], [sa], [delta], [subrot]) ...
  • rot_copies(n, [v], [cp], [sa], [delta], [subrot]) ...

Description: Given a number of XYZ rotation angles, or a list of angles and an axis v, rotates copies of the children to each of those angles.

ArgumentWhat it does
rotsA list of [X,Y,Z] rotation angles in degrees. If v is given, this will be a list of scalar angles in degrees to rotate around v.
vIf given, this is the vector to rotate around.
cpCenterpoint to rotate around.
nOptional number of evenly distributed copies, rotated around the ring. If given, overrides rots argument.
saStarting angle, in degrees. For use with n. Angle is in degrees counter-clockwise.
delta[X,Y,Z] amount to move away from cp before rotating. Makes rings of copies.
subrotIf false, don't sub-rotate children as they are copied around the ring.

Side Effects:

  • $ang is set to the rotation angle (or XYZ rotation triplet) of each child copy, and can be used to modify each child individually.
  • $idx is set to the index value of each child copy.

Example 1:

#cylinder(h=20, r1=5, r2=0);
rot_copies([[45,0,0],[0,45,90],[90,-45,270]]) cylinder(h=20, r1=5, r2=0);

rot_copies() Example 1

Example 2:

rot_copies([45, 90, 135], v=V_DOWN+V_BACK)
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

rot_copies() Example 2

Example 3:

rot_copies(n=6, v=V_DOWN+V_BACK)
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

rot_copies() Example 3

Example 4:

rot_copies(n=6, v=V_DOWN+V_BACK, delta=[10,0,0])
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

rot_copies() Example 4

Example 5:

rot_copies(n=6, v=V_UP+V_FWD, delta=[10,0,0], sa=45)
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

rot_copies() Example 5

Example 6:

rot_copies(n=6, v=V_DOWN+V_BACK, delta=[20,0,0], subrot=false)
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

rot_copies() Example 6


xrot_copies()

Usage:

  • xrot_copies(rots, [r], [cp], [sa], [subrot]) ...
  • xrot_copies(n, [r], [cp], [sa], [subrot]) ...

Description: Given an array of angles, rotates copies of the children to each of those angles around the X axis.

ArgumentWhat it does
rotsOptional array of rotation angles, in degrees, to make copies at.
cpCenterpoint to rotate around.
nOptional number of evenly distributed copies to be rotated around the ring. If given, overrides rots argument.
saStarting angle, in degrees. For use with n. Angle is in degrees counter-clockwise from Y+, when facing the origin from X+. First unrotated copy is placed at that angle.
rRadius to move children back, away from cp, before rotating. Makes rings of copies.
subrotIf false, don't sub-rotate children as they are copied around the ring.

Side Effects:

  • $ang is set to the rotation angle of each child copy, and can be used to modify each child individually.

Example 1:

xrot_copies([180, 270, 315])
    cylinder(h=20, r1=5, r2=0);
color("red",0.333) cylinder(h=20, r1=5, r2=0);

xrot_copies() Example 1

Example 2:

xrot_copies(n=6)
    cylinder(h=20, r1=5, r2=0);
color("red",0.333) cylinder(h=20, r1=5, r2=0);

xrot_copies() Example 2

Example 3:

xrot_copies(n=6, r=10)
    xrot(-90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) xrot(-90) cylinder(h=20, r1=5, r2=0);

xrot_copies() Example 3

Example 4:

xrot_copies(n=6, r=10, sa=45)
    xrot(-90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) xrot(-90) cylinder(h=20, r1=5, r2=0);

xrot_copies() Example 4

Example 5:

xrot_copies(n=6, r=20, subrot=false)
    xrot(-90) cylinder(h=20, r1=5, r2=0, center=true);
color("red",0.333) xrot(-90) cylinder(h=20, r1=5, r2=0, center=true);

xrot_copies() Example 5


yrot_copies()

Usage:

  • yrot_copies(rots, [r], [cp], [sa], [subrot]) ...
  • yrot_copies(n, [r], [cp], [sa], [subrot]) ...

Description: Given an array of angles, rotates copies of the children to each of those angles around the Y axis.

ArgumentWhat it does
rotsOptional array of rotation angles, in degrees, to make copies at.
cpCenterpoint to rotate around.
nOptional number of evenly distributed copies to be rotated around the ring. If given, overrides rots argument.
saStarting angle, in degrees. For use with n. Angle is in degrees counter-clockwise from X-, when facing the origin from Y+.
rRadius to move children left, away from cp, before rotating. Makes rings of copies.
subrotIf false, don't sub-rotate children as they are copied around the ring.

Side Effects:

  • $ang is set to the rotation angle of each child copy, and can be used to modify each child individually.

Example 1:

yrot_copies([180, 270, 315])
    cylinder(h=20, r1=5, r2=0);
color("red",0.333) cylinder(h=20, r1=5, r2=0);

yrot_copies() Example 1

Example 2:

yrot_copies(n=6)
    cylinder(h=20, r1=5, r2=0);
color("red",0.333) cylinder(h=20, r1=5, r2=0);

yrot_copies() Example 2

Example 3:

yrot_copies(n=6, r=10)
    yrot(-90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(-90) cylinder(h=20, r1=5, r2=0);

yrot_copies() Example 3

Example 4:

yrot_copies(n=6, r=10, sa=45)
    yrot(-90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(-90) cylinder(h=20, r1=5, r2=0);

yrot_copies() Example 4

Example 5:

yrot_copies(n=6, r=20, subrot=false)
    yrot(-90) cylinder(h=20, r1=5, r2=0, center=true);
color("red",0.333) yrot(-90) cylinder(h=20, r1=5, r2=0, center=true);

yrot_copies() Example 5


zrot_copies()

Usage:

  • zrot_copies(rots, [r], [cp], [sa], [subrot]) ...
  • zrot_copies(n, [r], [cp], [sa], [subrot]) ...

Description: Given an array of angles, rotates copies of the children to each of those angles around the Z axis.

ArgumentWhat it does
rotsOptional array of rotation angles, in degrees, to make copies at.
cpCenterpoint to rotate around.
nOptional number of evenly distributed copies to be rotated around the ring. If given, overrides rots argument.
saStarting angle, in degrees. For use with n. Angle is in degrees counter-clockwise from X+, when facing the origin from Z+.
rRadius to move children right, away from cp, before rotating. Makes rings of copies.
subrotIf false, don't sub-rotate children as they are copied around the ring.

Side Effects:

  • $ang is set to the rotation angle of each child copy, and can be used to modify each child individually.

Example 1:

zrot_copies([180, 270, 315])
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

zrot_copies() Example 1

Example 2:

zrot_copies(n=6)
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

zrot_copies() Example 2

Example 3:

zrot_copies(n=6, r=10)
    yrot(90) cylinder(h=20, r1=5, r2=0);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);

zrot_copies() Example 3

Example 4:

zrot_copies(n=6, r=20, sa=45)
    yrot(90) cylinder(h=20, r1=5, r2=0, center=true);
color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0, center=true);

zrot_copies() Example 4

Example 5:

zrot_copies(n=6, r=20, subrot=false)
    yrot(-90) cylinder(h=20, r1=5, r2=0, center=true);
color("red",0.333) yrot(-90) cylinder(h=20, r1=5, r2=0, center=true);

zrot_copies() Example 5


xring()

Usage:

  • xring(n, r, [sa], [cp], [rot]) ...

Description: Distributes n copies of the given children on a circle of radius r around the X axis. If rot is true, each copy is rotated in place to keep the same side towards the center. The first, unrotated copy will be at the starting angle sa.

ArgumentWhat it does
nNumber of copies of children to distribute around the circle. (Default: 2)
rRadius of ring to distribute children around. (Default: 0)
saStart angle for first (unrotated) copy. (Default: 0)
cpCenterpoint of ring. Default: [0,0,0]
rotIf true, rotate each copy to keep the same side towards the center of the ring. Default: true.

Side Effects:

  • $ang is set to the rotation angle of each child copy, and can be used to modify each child individually.
  • $idx is set to the index value of each child copy.

Example 1:

xring(n=6, r=10) xrot(-90) cylinder(h=20, r1=5, r2=0);

xring() Example 1

Example 2:

xring(n=6, r=10, sa=45) xrot(-90) cylinder(h=20, r1=5, r2=0);

xring() Example 2

Example 3:

xring(n=6, r=20, rot=false) cylinder(h=20, r1=6, r2=0, center=true);

xring() Example 3


yring()

Usage:

  • yring(n, r, [sa], [cp], [rot]) ...

Description: Distributes n copies of the given children on a circle of radius r around the Y axis. If rot is true, each copy is rotated in place to keep the same side towards the center. The first, unrotated copy will be at the starting angle sa.

ArgumentWhat it does
nNumber of copies of children to distribute around the circle. (Default: 2)
rRadius of ring to distribute children around. (Default: 0)
saStart angle for first (unrotated) copy. (Default: 0)
cpCenterpoint of ring. Default: [0,0,0]
rotIf true, rotate each copy to keep the same side towards the center of the ring. Default: true.

Side Effects:

  • $ang is set to the rotation angle of each child copy, and can be used to modify each child individually.
  • $idx is set to the index value of each child copy.

Example 1:

yring(n=6, r=10) yrot(-90) cylinder(h=20, r1=5, r2=0);

yring() Example 1

Example 2:

yring(n=6, r=10, sa=45) yrot(-90) cylinder(h=20, r1=5, r2=0);

yring() Example 2

Example 3:

yring(n=6, r=20, rot=false) cylinder(h=20, r1=6, r2=0, center=true);

yring() Example 3


zring()

Usage:

  • zring(r, n, [sa], [cp], [rot]) ...

Description: Distributes n copies of the given children on a circle of radius r around the Z axis. If rot is true, each copy is rotated in place to keep the same side towards the center. The first, unrotated copy will be at the starting angle sa.

ArgumentWhat it does
nNumber of copies of children to distribute around the circle. (Default: 2)
rRadius of ring to distribute children around. (Default: 0)
saStart angle for first (unrotated) copy. (Default: 0)
cpCenterpoint of ring. Default: [0,0,0]
rotIf true, rotate each copy to keep the same side towards the center of the ring. Default: true.

Side Effects:

  • $ang is set to the relative angle from cp of each child copy, and can be used to modify each child individually.
  • $idx is set to the index value of each child copy.

Example 1:

zring(n=6, r=10) yrot(90) cylinder(h=20, r1=5, r2=0);

zring() Example 1

Example 2:

zring(n=6, r=10, sa=45) yrot(90) cylinder(h=20, r1=5, r2=0);

zring() Example 2

Example 3:

zring(n=6, r=20, rot=false) yrot(90) cylinder(h=20, r1=6, r2=0, center=true);

zring() Example 3


arc_of()

Usage:

  • arc_of(r|d, n, [sa], [ea], [rot]
  • arc_of(rx|dx, ry|dy, n, [sa], [ea], [rot]

Description: Evenly distributes n duplicate children around an ovoid arc on the XY plane.

ArgumentWhat it does
nnumber of copies to distribute around the circle. (Default: 6)
rradius of circle (Default: 1)
rxradius of ellipse on X axis. Used instead of r.
ryradius of ellipse on Y axis. Used instead of r.
ddiameter of circle. (Default: 2)
dxdiameter of ellipse on X axis. Used instead of d.
dydiameter of ellipse on Y axis. Used instead of d.
rotwhether to rotate the copied children. (Default: false)
sastarting angle. (Default: 0.0)
eaending angle. Will distribute copies CCW from sa to ea. (Default: 360.0)

Side Effects:

  • $ang is set to the rotation angle of each child copy, and can be used to modify each child individually.
  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
  • $idx is set to the index value of each child copy.

Example 1:

#cube(size=[10,3,3],center=true);
arc_of(d=40, n=5) cube(size=[10,3,3],center=true);

arc_of() Example 1

Example 2:

#cube(size=[10,3,3],center=true);
arc_of(d=40, n=5, sa=45, ea=225) cube(size=[10,3,3],center=true);

arc_of() Example 2

Example 3:

#cube(size=[10,3,3],center=true);
arc_of(r=15, n=8, rot=false) cube(size=[10,3,3],center=true);

arc_of() Example 3

Example 4:

#cube(size=[10,3,3],center=true);
arc_of(rx=20, ry=10, n=8) cube(size=[10,3,3],center=true);

arc_of() Example 4


ovoid_spread()

Usage:

  • ovoid_spread(r|d, n, [cone_ang], [scale], [perp]) ...

Description: Spreads children semi-evenly over the surface of a sphere.

ArgumentWhat it does
rRadius of the sphere to distribute over
dDiameter of the sphere to distribute over
nHow many copies to evenly spread over the surface.
cone_angAngle of the cone, in degrees, to limit how much of the sphere gets covered. For full sphere coverage, use 180. Measured pre-scaling. Default: 180
scaleThe [X,Y,Z] scaling factors to reshape the sphere being covered.
perpIf true, rotate children to be perpendicular to the sphere surface. Default: true

Side Effects:

  • $pos is set to the relative post-scaled centerpoint of each child copy, and can be used to modify each child individually.
  • $theta is set to the theta angle of the child from the center of the sphere.
  • $phi is set to the pre-scaled phi angle of the child from the center of the sphere.
  • $rad is set to the pre-scaled radial distance of the child from the center of the sphere.
  • $idx is set to the index number of each child being copied.

Example 1:

ovoid_spread(n=250, d=100, cone_ang=45, scale=[3,3,1])
    cylinder(d=10, h=10, center=false);

ovoid_spread() Example 1

Example 2:

ovoid_spread(n=500, d=100, cone_ang=180)
    color(normalize(point3d(vabs($pos))))
        cylinder(d=8, h=10, center=false);

ovoid_spread() Example 2


7. Reflectional Distributors

mirror_copy()

Usage:

  • mirror_copy(v, [cp], [offset]) ...

Description: Makes a copy of the children, mirrored across the given plane.

ArgumentWhat it does
vThe normal vector of the plane to mirror across.
offsetdistance to offset away from the plane.
cpA point that lies on the mirroring plane.

Side Effects:

  • $orig is true for the original instance of children. False for the copy.
  • $idx is set to the index value of each copy.

Example 1:

mirror_copy([1,-1,0]) zrot(-45) yrot(90) cylinder(d1=10, d2=0, h=20);
color("blue",0.25) zrot(-45) cube([0.01,15,15], center=true);

mirror_copy() Example 1

Example 2:

mirror_copy([1,1,0], offset=5) rot(a=90,v=[-1,1,0]) cylinder(d1=10, d2=0, h=20);
color("blue",0.25) zrot(45) cube([0.01,15,15], center=true);

mirror_copy() Example 2

Example 3:

mirror_copy(V_UP+V_BACK, cp=[0,-5,-5]) rot(from=V_UP, to=V_BACK+V_UP) cylinder(d1=10, d2=0, h=20);
color("blue",0.25) translate([0,-5,-5]) rot(from=V_UP, to=V_BACK+V_UP) cube([15,15,0.01], center=true);

mirror_copy() Example 3


xflip_copy()

Usage:

  • xflip_copy([cp], [offset]) ...

Description: Makes a copy of the children, mirrored across the X axis.

ArgumentWhat it does
offsetDistance to offset children right, before copying.
cpA point that lies on the mirroring plane.

Side Effects:

  • $orig is true for the original instance of children. False for the copy.
  • $idx is set to the index value of each copy.

Example 1:

xflip_copy() yrot(90) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) cube([0.01,15,15], center=true);

xflip_copy() Example 1

Example 2:

xflip_copy(offset=5) yrot(90) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) cube([0.01,15,15], center=true);

xflip_copy() Example 2

Example 3:

xflip_copy(cp=[-5,0,0]) yrot(90) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) left(5) cube([0.01,15,15], center=true);

xflip_copy() Example 3


yflip_copy()

Usage:

  • yflip_copy([cp], [offset]) ...

Description: Makes a copy of the children, mirrored across the Y axis.

ArgumentWhat it does
offsetDistance to offset children back, before copying.
cpA point that lies on the mirroring plane.

Side Effects:

  • $orig is true for the original instance of children. False for the copy.
  • $idx is set to the index value of each copy.

Example 1:

yflip_copy() xrot(-90) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) cube([15,0.01,15], center=true);

yflip_copy() Example 1

Example 2:

yflip_copy(offset=5) xrot(-90) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) cube([15,0.01,15], center=true);

yflip_copy() Example 2

Example 3:

yflip_copy(cp=[0,-5,0]) xrot(-90) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) fwd(5) cube([15,0.01,15], center=true);

yflip_copy() Example 3


zflip_copy()

Usage:

  • zflip_copy([cp], [offset]) ...
  • $idx is set to the index value of each copy.

Description: Makes a copy of the children, mirrored across the Z axis.

ArgumentWhat it does
offsetDistance to offset children up, before copying.
cpA point that lies on the mirroring plane.

Side Effects:

  • $orig is true for the original instance of children. False for the copy.

Example 1:

zflip_copy() cylinder(h=20, r1=4, r2=0);
color("blue",0.25) cube([15,15,0.01], center=true);

zflip_copy() Example 1

Example 2:

zflip_copy(offset=5) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) cube([15,15,0.01], center=true);

zflip_copy() Example 2

Example 3:

zflip_copy(cp=[0,0,-5]) cylinder(h=20, r1=4, r2=0);
color("blue",0.25) down(5) cube([15,15,0.01], center=true);

zflip_copy() Example 3


8. Mutators

half_of()

Usage:

  • half_of(v, [cp], [s]) ...

Description: Slices an object at a cut plane, and masks away everything that is on one side.

ArgumentWhat it does
vNormal of plane to slice at. Keeps everything on the side the normal points to. Default: [0,0,1] (V_UP)
cpIf given as a scalar, moves the cut plane along the normal by the given amount. If given as a point, specifies a point on the cut plane. This can be used to shift where it slices the object at. Default: [0,0,0]
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes a 2D operation. When planar, a v of V_UP or V_DOWN becomes equivalent of V_BACK and V_FWD respectively.

Example 1:

half_of(V_DOWN+V_BACK, cp=[0,-10,0]) cylinder(h=40, r1=10, r2=0, center=false);

half_of() Example 1

Example 2:

half_of(V_DOWN+V_LEFT, s=200) sphere(d=150);

half_of() Example 2

Example 3:

half_of([1,1], planar=true) circle(d=50);

half_of() Example 3


top_half()

Usage:

  • top_half([z|cp], [s]) ...

Description: Slices an object at a horizontal X-Y cut plane, and masks away everything that is below it.

ArgumentWhat it does
cpIf given as a scalar, moves the cut plane up by the given amount. If given as a point, specifies a point on the cut plane. Default: [0,0,0]
zThe Z coordinate of the cut-plane, if given. Use instead of cp.
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes equivalent to a planar back_half().

Example 1:

top_half() sphere(r=20);

top_half() Example 1

Example 2:

top_half(z=5) sphere(r=20);

top_half() Example 2

Example 3:

top_half(cp=5) sphere(r=20);

top_half() Example 3

Example 4:

top_half(cp=[0,0,-8]) sphere(r=20);

top_half() Example 4

Example 5:

top_half(planar=true) circle(r=20);

top_half() Example 5


bottom_half()

Usage:

  • bottom_half([z|cp], [s]) ...

Description: Slices an object at a horizontal X-Y cut plane, and masks away everything that is above it.

ArgumentWhat it does
cpIf given as a scalar, moves the cut plane down by the given amount. If given as a point, specifies a point on the cut plane. Default: [0,0,0]
zThe Z coordinate of the cut-plane, if given. Use instead of cp.
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes equivalent to a planar front_half().

Example 1:

bottom_half() sphere(r=20);

bottom_half() Example 1

Example 2:

bottom_half(z=-10) sphere(r=20);

bottom_half() Example 2

Example 3:

bottom_half(cp=-10) sphere(r=20);

bottom_half() Example 3

Example 4:

bottom_half(cp=[0,0,10]) sphere(r=20);

bottom_half() Example 4

Example 5:

bottom_half(planar=true) circle(r=20);

bottom_half() Example 5


left_half()

Usage:

  • left_half([x|cp], [s]) ...

Description: Slices an object at a vertical Y-Z cut plane, and masks away everything that is right of it.

ArgumentWhat it does
cpIf given as a scalar, moves the cut plane left by the given amount. If given as a point, specifies a point on the cut plane. Default: [0,0,0]
xThe X coordinate of the cut-plane, if given. Use instead of cp.
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes a 2D operation.

Example 1:

left_half() sphere(r=20);

left_half() Example 1

Example 2:

left_half(x=-8) sphere(r=20);

left_half() Example 2

Example 3:

left_half(cp=-8) sphere(r=20);

left_half() Example 3

Example 4:

left_half(cp=[8,0,0]) sphere(r=20);

left_half() Example 4

Example 5:

left_half(planar=true) circle(r=20);

left_half() Example 5


right_half()

Usage:

  • right_half([x|cp], [s]) ...

Description: Slices an object at a vertical Y-Z cut plane, and masks away everything that is left of it.

ArgumentWhat it does
cpIf given as a scalar, moves the cut plane right by the given amount. If given as a point, specifies a point on the cut plane. Default: [0,0,0]
xThe X coordinate of the cut-plane, if given. Use instead of cp.
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes a 2D operation.

Example 1:

right_half() sphere(r=20);

right_half() Example 1

Example 2:

right_half(x=-5) sphere(r=20);

right_half() Example 2

Example 3:

right_half(cp=-5) sphere(r=20);

right_half() Example 3

Example 4:

right_half(cp=[-5,0,0]) sphere(r=20);

right_half() Example 4

Example 5:

right_half(planar=true) circle(r=20);

right_half() Example 5


front_half()

Usage:

  • front_half([y|cp], [s]) ...

Description: Slices an object at a vertical X-Z cut plane, and masks away everything that is behind it.

ArgumentWhat it does
cpIf given as a scalar, moves the cut plane forward by the given amount. If given as a point, specifies a point on the cut plane. Default: [0,0,0]
yThe Y coordinate of the cut-plane, if given. Use instead of cp.
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes a 2D operation.

Example 1:

front_half() sphere(r=20);

front_half() Example 1

Example 2:

front_half(y=5) sphere(r=20);

front_half() Example 2

Example 3:

front_half(cp=5) sphere(r=20);

front_half() Example 3

Example 4:

front_half(cp=[0,5,0]) sphere(r=20);

front_half() Example 4

Example 5:

front_half(planar=true) circle(r=20);

front_half() Example 5


back_half()

Usage:

  • back_half([y|cp], [s]) ...

Description: Slices an object at a vertical X-Z cut plane, and masks away everything that is in front of it.

ArgumentWhat it does
cpIf given as a scalar, moves the cut plane back by the given amount. If given as a point, specifies a point on the cut plane. Default: [0,0,0]
yThe Y coordinate of the cut-plane, if given. Use instead of cp.
sMask size to use. Use a number larger than twice your object's largest axis. If you make this too large, it messes with centering your view. Default: 100
planarIf true, this becomes a 2D operation.

Example 1:

back_half() sphere(r=20);

back_half() Example 1

Example 2:

back_half(y=8) sphere(r=20);

back_half() Example 2

Example 3:

back_half(cp=8) sphere(r=20);

back_half() Example 3

Example 4:

back_half(cp=[0,-10,0]) sphere(r=20);

back_half() Example 4

Example 5:

back_half(planar=true) circle(r=20);

back_half() Example 5


chain_hull()

Usage:

  • chain_hull() ...

Description: Performs hull operations between consecutive pairs of children, then unions all of the hull results. This can be a very slow operation, but it can provide results that are hard to get otherwise.

Example:

chain_hull() {
    cube(5, center=true);
    translate([30, 0, 0]) sphere(d=15);
    translate([60, 30, 0]) cylinder(d=10, h=20);
    translate([60, 60, 0]) cube([10,1,20], center=false);
}

chain_hull() Example


extrude_arc()

Usage:

  • extrude_arc(arc, r|d, [sa], [caps], [orient], [align], [masksize]) ...

Description: Extrudes 2D shapes around a partial circle arc, with optional rounded caps. This is mostly useful for backwards compatability with older OpenSCAD versions without the angle argument in rotate_extrude.

ArgumentWhat it does
arcNumber of degrees to traverse.
saStart angle in degrees.
rRadius of arc.
dDiameter of arc.
orientThe axis to align to. Use ORIENT_ constants from constants.scad
alignThe side of the origin the part should be aligned with. Use V_ constants from constants.scad
masksizesize of mask used to clear unused part of circle arc. should be larger than height or width of 2D shapes to extrude.
capsIf true, spin the 2D shapes to make rounded caps the ends of the arc.
convexityMax number of times a ray passes through the 2D shape's walls.

Example:

pts=[[-5/2, -5], [-5/2, 0], [-5/2-3, 5], [5/2+3, 5], [5/2, 0], [5/2, -5]];
#polygon(points=pts);
extrude_arc(arc=270, sa=45, r=40, caps=true, convexity=4, $fa=2, $fs=2) {
    polygon(points=pts);
}

extrude_arc() Example


9. 2D Mutators

round2d()

Usage:

  • round2d(r) ...
  • round2d(or) ...
  • round2d(ir) ...
  • round2d(or, ir) ...

Description: Rounds an arbitrary 2d objects. Giving r rounds all concave and convex corners. Giving just ir rounds just concave corners. Giving just or rounds convex corners. Giving both ir and or can let you round to different radii for concave and convex corners. The 2d object must not have any parts narrower than twice the or radius. Such parts will disappear.

ArgumentWhat it does
rRadius to round all concave and convex corners to.
orRadius to round only outside (convex) corners to. Use instead of r.
irRadius to round/fillet only inside (concave) corners to. Use instead of r.

Example 1:

round2d(r=10) {square([40,100], center=true); square([100,40], center=true);}

round2d() Example 1

Example 2:

round2d(or=10) {square([40,100], center=true); square([100,40], center=true);}

round2d() Example 2

Example 3:

round2d(ir=10) {square([40,100], center=true); square([100,40], center=true);}

round2d() Example 3

Example 4:

round2d(or=16,ir=8) {square([40,100], center=true); square([100,40], center=true);}

round2d() Example 4


shell2d()

Usage:

  • shell2d(thickness, [or], [ir], [fill], [round])

Description: Creates a hollow shell from 2d children, with optional rounding.

ArgumentWhat it does
thicknessThickness of the shell. Positive to expand outward, negative to shrink inward, or a two-element list to do both.
orRadius to round convex corners/pointy bits on the outside of the shell.
irRadius to round/fillet concave corners on the outside of the shell.
roundRadius to round convex corners/pointy bits on the inside of the shell.
fillRadius to round/fillet concave corners on the inside of the shell.

Example 1:

shell2d(10) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 1

Example 2:

shell2d(-10) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 2

Example 3:

shell2d([-10,10]) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 3

Example 4:

shell2d(10,or=10) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 4

Example 5:

shell2d(10,ir=10) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 5

Example 6:

shell2d(10,round=10) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 6

Example 7:

shell2d(10,fill=10) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 7

Example 8:

shell2d(8,or=16,ir=8,round=16,fill=8) {square([40,100], center=true); square([100,40], center=true);}

shell2d() Example 8


10. Miscellaneous

orient_and_align()

Usage:

  • orient_and_align(size, [orient], [align], [center], [noncentered], [orig_orient], [orig_align], [alignments]) ...

Description: Takes a vertically oriented shape, and re-orients and aligns it. This is useful for making a custom shape available in various orientations and alignments without extra translate()s and rotate()s. Children should be vertically (Z-axis) oriented, and centered. Non-extremity alignment points should be named via the alignments arg. Named alignments, as well as ALIGN_NEG/ALIGN_POS are aligned pre-rotation.

ArgumentWhat it does
sizeThe size of the part.
orientThe axis to align to. Use ORIENT_ constants from constants.scad
alignThe side of the origin the part should be aligned with.
centerIf given, overrides align. If true, centers vertically. If false, align will be set to the value in noncentered.
noncenteredThe value to set align to if center == false. Default: V_UP.
orig_orientThe original orientation of the part. Default: ORIENT_Z.
orig_alignThe original alignment of the part. Default: V_CENTER.
alignmentsA list of ["name", [X,Y,Z]] alignment-label/offset pairs.

Example:

#cylinder(d=5, h=10);
orient_and_align([5,5,10], orient=ORIENT_Y, align=V_BACK, orig_align=V_UP) cylinder(d=5, h=10);

orient_and_align() Example


11. Deprecations

translate_copies()

DEPRECATED, use place_copies() instead.

Usage:

  • translate_copies(a) ...

Description: Makes copies of the given children at each of the given offsets.

ArgumentWhat it does
aarray of XYZ offset vectors. Default 0,0,0

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.

line_of()

DEPRECATED, use spread(p1,p2) instead

Usage:

  • line_of(p1, p2, [n]) ...

Description: Evenly distributes n duplicate children along an XYZ line.

ArgumentWhat it does
p1starting point of line. (Default: [0,0,0])
p2ending point of line. (Default: [10,0,0])
nnumber of copies to distribute along the line. (Default: 2)

Side Effects:

  • $pos is set to the relative centerpoint of each child copy, and can be used to modify each child individually.

grid_of()

DEPRECATED, use grid3d() instead.

Usage:

  • grid_of(n, spacing) ...
  • grid_of(n=[Xn,Yn,Zn], spacing=[dX,dY,dZ]) ...
  • grid_of([xa], [ya], [za]) ...

Description: Makes a 3D grid of duplicate children.

ArgumentWhat it does
xaarray or range of X-axis values to offset by. (Default: [0])
yaarray or range of Y-axis values to offset by. (Default: [0])
zaarray or range of Z-axis values to offset by. (Default: [0])
nOptional number of copies to have per axis.
spacingspacing of copies per axis. Use with n.

Clone this wiki locally