Renamed all V_ constants. Removed ALIGN_ constants.

This commit is contained in:
Revar Desmera 2019-04-18 23:32:17 -07:00
parent 08711565e7
commit 6b0e796462
19 changed files with 340 additions and 416 deletions

View file

@ -24,7 +24,7 @@ Args | What it is
fillet | Radius of rounding for interior or exterior edges. fillet | Radius of rounding for interior or exterior edges.
chamfer | Size of chamfers/bevels for interior or exterior edges. chamfer | Size of chamfers/bevels for interior or exterior edges.
orient | Axis a part should be oriented along. Given as an XYZ triplet of rotation angles. It is recommended that you use the `ORIENT_` constants from `constants.scad`. Default is usually `ORIENT_Z` for vertical orientation. orient | Axis a part should be oriented along. Given as an XYZ triplet of rotation angles. It is recommended that you use the `ORIENT_` constants from `constants.scad`. Default is usually `ORIENT_Z` for vertical orientation.
align | Side of the origin that the part should be on. Given as a vector away from the origin. It is recommended that you use the `V_` constants from `constants.scad`. Default is usually `V_ZERO` for centered. align | Side of the origin that the part should be on. Given as a vector away from the origin. It is recommended that you use the constants from `constants.scad`. Default is usually `CENTER` for centered.
## Examples ## Examples

View file

@ -446,7 +446,7 @@ module bezier_polygon(bezier, splinesteps=16, N=3) {
// slices = Number of vertical slices to use for twisted extrusion. default=20 // slices = Number of vertical slices to use for twisted extrusion. default=20
// center = If true, the extruded solid is centered vertically at z=0. // center = If true, the extruded solid is centered vertically at z=0.
// orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the extrusion. Use the `V_` constants from `constants.scad`. Default: `ALIGN_POS`. // align = Alignment of the extrusion. Use the constants from `constants.scad`. Default: `UP`.
// Example: // Example:
// bez = [ // bez = [
// [-10, 0], [-15, -5], // [-10, 0], [-15, -5],
@ -456,7 +456,7 @@ module bezier_polygon(bezier, splinesteps=16, N=3) {
// [ 25, -15], [-10, 0] // [ 25, -15], [-10, 0]
// ]; // ];
// linear_extrude_bezier(bez, height=20, splinesteps=32); // linear_extrude_bezier(bez, height=20, splinesteps=32);
module linear_extrude_bezier(bezier, height=100, splinesteps=16, N=3, center=undef, convexity=undef, twist=undef, slices=undef, scale=undef, orient=ORIENT_Z, align=ALIGN_POS) { module linear_extrude_bezier(bezier, height=100, splinesteps=16, N=3, center=undef, convexity=undef, twist=undef, slices=undef, scale=undef, orient=ORIENT_Z, align=UP) {
maxx = max([for (pt = bezier) abs(pt[0])]); maxx = max([for (pt = bezier) abs(pt[0])]);
maxy = max([for (pt = bezier) abs(pt[1])]); maxy = max([for (pt = bezier) abs(pt[1])]);
orient_and_align([maxx*2,maxy*2,height], orient, align) { orient_and_align([maxx*2,maxy*2,height], orient, align) {
@ -479,7 +479,7 @@ module linear_extrude_bezier(bezier, height=100, splinesteps=16, N=3, center=und
// convexity = max number of walls a line could pass through, for preview. default=10 // convexity = max number of walls a line could pass through, for preview. default=10
// angle = Degrees of sweep to make. Default: 360 // angle = Degrees of sweep to make. Default: 360
// orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the extrusion. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the extrusion. Use the constants from `constants.scad`. Default: `CENTER`.
// Example(FlatSpin): // Example(FlatSpin):
// path = [ // path = [
// [ 0, 10], [ 50, 0], [ 50, 40], // [ 0, 10], [ 50, 0], [ 50, 40],
@ -489,7 +489,7 @@ module linear_extrude_bezier(bezier, height=100, splinesteps=16, N=3, center=und
// [ 0, 10] // [ 0, 10]
// ]; // ];
// revolve_bezier(path, splinesteps=32, $fn=180); // revolve_bezier(path, splinesteps=32, $fn=180);
module revolve_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_X, align=V_CENTER) module revolve_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_X, align=CENTER)
{ {
maxx = max([for (pt = bezier) abs(pt[0])]); maxx = max([for (pt = bezier) abs(pt[0])]);
maxy = max([for (pt = bezier) abs(pt[1])]); maxy = max([for (pt = bezier) abs(pt[1])]);
@ -515,7 +515,7 @@ module revolve_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, orie
// convexity = max number of walls a line could pass through, for preview. default=10 // convexity = max number of walls a line could pass through, for preview. default=10
// angle = Degrees of sweep to make. Default: 360 // angle = Degrees of sweep to make. Default: 360
// orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the extrusion. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the extrusion. Use the constants from `constants.scad`. Default: `CENTER`.
// Example(Spin): // Example(Spin):
// path = [ // path = [
// [ 0, 10], [ 50, 0], [ 50, 40], // [ 0, 10], [ 50, 0], [ 50, 40],
@ -525,7 +525,7 @@ module revolve_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, orie
// [ 0, 10] // [ 0, 10]
// ]; // ];
// rotate_extrude_bezier(path, splinesteps=32, $fn=180); // rotate_extrude_bezier(path, splinesteps=32, $fn=180);
module rotate_extrude_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_Z, align=V_CENTER) module rotate_extrude_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_Z, align=CENTER)
{ {
maxx = max([for (pt = bezier) abs(pt[0])]); maxx = max([for (pt = bezier) abs(pt[0])]);
maxy = max([for (pt = bezier) abs(pt[1])]); maxy = max([for (pt = bezier) abs(pt[1])]);
@ -550,11 +550,11 @@ module rotate_extrude_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=36
// convexity = max number of walls a line could pass through, for preview. default=10 // convexity = max number of walls a line could pass through, for preview. default=10
// angle = Degrees of sweep to make. Default: 360 // angle = Degrees of sweep to make. Default: 360
// orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the extrusion. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the extrusion. Use the constants from `constants.scad`. Default: `CENTER`.
// Example(FlatSpin): // Example(FlatSpin):
// path = [ [0, 10], [33, 10], [66, 40], [100, 40] ]; // path = [ [0, 10], [33, 10], [66, 40], [100, 40] ];
// revolve_bezier_solid_to_axis(path, splinesteps=32, $fn=72); // revolve_bezier_solid_to_axis(path, splinesteps=32, $fn=72);
module revolve_bezier_solid_to_axis(bezier, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_X, align=V_CENTER) { module revolve_bezier_solid_to_axis(bezier, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_X, align=CENTER) {
revolve_bezier(bezier=bezier_close_to_axis(bezier), splinesteps=splinesteps, N=N, convexity=convexity, angle=angle, orient=orient, align=align); revolve_bezier(bezier=bezier_close_to_axis(bezier), splinesteps=splinesteps, N=N, convexity=convexity, angle=angle, orient=orient, align=align);
} }
@ -572,11 +572,11 @@ module revolve_bezier_solid_to_axis(bezier, splinesteps=16, N=3, convexity=10, a
// convexity = max number of walls a line could pass through, for preview. default=10 // convexity = max number of walls a line could pass through, for preview. default=10
// angle = degrees of sweep to make. Default: 360 // angle = degrees of sweep to make. Default: 360
// orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the extrusion. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the extrusion. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the extrusion. Use the constants from `constants.scad`. Default: `CENTER`.
// Example(FlatSpin): // Example(FlatSpin):
// path = [ [0, 10], [33, 10], [66, 40], [100, 40] ]; // path = [ [0, 10], [33, 10], [66, 40], [100, 40] ];
// revolve_bezier_offset_shell(path, offset=1, splinesteps=32, $fn=72); // revolve_bezier_offset_shell(path, offset=1, splinesteps=32, $fn=72);
module revolve_bezier_offset_shell(bezier, offset=1, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_X, align=V_CENTER) { module revolve_bezier_offset_shell(bezier, offset=1, splinesteps=16, N=3, convexity=10, angle=360, orient=ORIENT_X, align=CENTER) {
revolve_bezier(bezier=bezier_offset(offset, bezier), splinesteps=splinesteps, N=N, orient=orient, align=align); revolve_bezier(bezier=bezier_offset(offset, bezier), splinesteps=splinesteps, N=N, orient=orient, align=align);
} }

View file

@ -45,116 +45,77 @@ PRINTER_SLOP = 0.20; // The printer specific amount of slop in mm to print with
// Section: Directional Vectors // Section: Directional Vectors
// Vectors useful for `rotate()`, `mirror()`, and `align` arguments for `cuboid()`, `cyl()`, etc. // Vectors useful for `rotate()`, `mirror()`, and `align` arguments for `cuboid()`, `cyl()`, etc.
// Constant: V_LEFT // Constant: LEFT
// Description: Vector pointing left. [-1,0,0] // Description: Vector pointing left. [-1,0,0]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_LEFT); // cuboid(20, align=LEFT);
V_LEFT = [-1, 0, 0]; LEFT = [-1, 0, 0];
// Constant: V_RIGHT // Constant: RIGHT
// Description: Vector pointing right. [1,0,0] // Description: Vector pointing right. [1,0,0]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_RIGHT); // cuboid(20, align=RIGHT);
V_RIGHT = [ 1, 0, 0]; RIGHT = [ 1, 0, 0];
// Constant: V_FWD // Constant: FWD
// Description: Vector pointing forward. [0,-1,0] // Description: Vector pointing forward. [0,-1,0]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_FWD); // cuboid(20, align=FWD);
V_FWD = [ 0, -1, 0]; FWD = [ 0, -1, 0];
// Constant: V_BACK // Constant: BACK
// Description: Vector pointing back. [0,1,0] // Description: Vector pointing back. [0,1,0]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_BACK); // cuboid(20, align=BACK);
V_BACK = [ 0, 1, 0]; BACK = [ 0, 1, 0];
// Constant: V_DOWN // Constant: DOWN
// Description: Vector pointing down. [0,0,-1] // Description: Vector pointing down. [0,0,-1]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_DOWN); // cuboid(20, align=DOWN);
V_DOWN = [ 0, 0, -1]; DOWN = [ 0, 0, -1];
// Constant: V_UP // Constant: UP
// Description: Vector pointing up. [0,0,1] // Description: Vector pointing up. [0,0,1]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_UP); // cuboid(20, align=UP);
V_UP = [ 0, 0, 1]; UP = [ 0, 0, 1];
// Constant: V_ALLPOS // Constant: ALLPOS
// Description: Vector pointing right, back, and up. [1,1,1] // Description: Vector pointing right, back, and up. [1,1,1]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_ALLPOS); // cuboid(20, align=ALLPOS);
V_ALLPOS = [ 1, 1, 1]; // Vector pointing X+,Y+,Z+. ALLPOS = [ 1, 1, 1]; // Vector pointing X+,Y+,Z+.
// Constant: V_ALLNEG // Constant: ALLNEG
// Description: Vector pointing left, forwards, and down. [-1,-1,-1] // Description: Vector pointing left, forwards, and down. [-1,-1,-1]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_ALLNEG); // cuboid(20, align=ALLNEG);
V_ALLNEG = [-1, -1, -1]; // Vector pointing X-,Y-,Z-. ALLNEG = [-1, -1, -1]; // Vector pointing X-,Y-,Z-.
// Constant: V_ZERO // Constant: CENTER
// Description: Zero vector. Centered. [0,0,0] // Description: Zero vector. Centered. [0,0,0]
// Example(3D): Usage with `align` // Example(3D): Usage with `align`
// cuboid(20, align=V_ZERO); // cuboid(20, align=CENTER);
V_ZERO = [ 0, 0, 0]; // Centered zero vector. CENTER = [ 0, 0, 0]; // Centered zero vector.
// Section: Vector Aliases // Section: Vector Aliases
// Useful aliases for use with `align`. // Useful aliases for use with `align`.
V_CENTER = V_ZERO; // Centered, alias to `V_ZERO`. ABOVE = UP; // Vector pointing up, alias to `UP`.
V_ABOVE = V_UP; // Vector pointing up, alias to `V_UP`. BELOW = DOWN; // Vector pointing down, alias to `DOWN`.
V_BELOW = V_DOWN; // Vector pointing down, alias to `V_DOWN`. BEFORE = FWD; // Vector pointing forward, alias to `FWD`.
V_BEFORE = V_FWD; // Vector pointing forward, alias to `V_FWD`. BEHIND = BACK; // Vector pointing back, alias to `BACK`.
V_BEHIND = V_BACK; // Vector pointing back, alias to `V_BACK`.
V_TOP = V_UP; // Vector pointing up, alias to `V_UP`. TOP = UP; // Vector pointing up, alias to `UP`.
V_BOTTOM = V_DOWN; // Vector pointing down, alias to `V_DOWN`. BOTTOM = DOWN; // Vector pointing down, alias to `DOWN`.
V_FRONT = V_FWD; // Vector pointing forward, alias to `V_FWD`. FRONT = FWD; // Vector pointing forward, alias to `FWD`.
V_REAR = V_BACK; // Vector pointing back, alias to `V_BACK`. REAR = BACK; // Vector pointing back, alias to `BACK`.
FORWARD = FWD; // Vector pointing forward, alias to `FWD`.
// Section: Pre-Orientation Alignments
// Constants for pre-orientation alignments.
// Constant: ALIGN_POS
// Description: Align the axis-positive end to the origin.
// Example(3D): orient=ORIENT_X
// cyl(d1=10, d2=5, h=20, orient=ORIENT_X, align=ALIGN_POS);
// Example(3D): orient=ORIENT_Y
// cyl(d1=10, d2=5, h=20, orient=ORIENT_Y, align=ALIGN_POS);
// Example(3D): orient=ORIENT_Z
// cyl(d1=10, d2=5, h=20, orient=ORIENT_Z, align=ALIGN_POS);
// Example(3D): orient=ORIENT_XNEG
// cyl(d1=10, d2=5, h=20, orient=ORIENT_XNEG, align=ALIGN_POS);
// Example(3D): orient=ORIENT_YNEG
// cyl(d1=10, d2=5, h=20, orient=ORIENT_YNEG, align=ALIGN_POS);
// Example(3D): orient=ORIENT_ZNEG
// cyl(d1=10, d2=5, h=20, orient=ORIENT_ZNEG, align=ALIGN_POS);
ALIGN_POS = 1;
ALIGN_CENTER = 0; // Align centered.
// Constant: ALIGN_NEG
// Description: Align the axis-negative end to the origin.
// Example(3D): orient=ORIENT_X
// cyl(d1=10, d2=5, h=20, orient=ORIENT_X, align=ALIGN_NEG);
// Example(3D): orient=ORIENT_Y
// cyl(d1=10, d2=5, h=20, orient=ORIENT_Y, align=ALIGN_NEG);
// Example(3D): orient=ORIENT_Z
// cyl(d1=10, d2=5, h=20, orient=ORIENT_Z, align=ALIGN_NEG);
// Example(3D): orient=ORIENT_XNEG
// cyl(d1=10, d2=5, h=20, orient=ORIENT_XNEG, align=ALIGN_NEG);
// Example(3D): orient=ORIENT_YNEG
// cyl(d1=10, d2=5, h=20, orient=ORIENT_YNEG, align=ALIGN_NEG);
// Example(3D): orient=ORIENT_ZNEG
// cyl(d1=10, d2=5, h=20, orient=ORIENT_ZNEG, align=ALIGN_NEG);
ALIGN_NEG = -1;
// CommonCode: // CommonCode:
// orientations = [ // orientations = [
@ -346,7 +307,7 @@ function corner_edge_count(edges, v) =
$color = undef; $color = undef;
$overlap = 0.01; $overlap = 0.01;
$attach_to = undef; $attach_to = undef;
$attach_conn = ["center", V_ZERO, V_UP, 0]; $attach_conn = ["center", CENTER, UP, 0];
$parent_size = undef; $parent_size = undef;
$parent_size2 = undef; $parent_size2 = undef;
$parent_shift = [0,0]; $parent_shift = [0,0];

View file

@ -183,16 +183,16 @@ module debug_polyhedron(points, faces, convexity=10, txtsize=1, disabled=false)
function all_conns(type="cube") = function all_conns(type="cube") =
assert(in_list(type,["cube", "cylinder", "sphere"])) assert(in_list(type,["cube", "cylinder", "sphere"]))
let ( let (
zs = ["top", "bottom"], zs = [TOP, BOTTOM],
ys = ["front", "back"], ys = [FRONT, BACK],
xs = ["left", "right"] xs = [LEFT, RIGHT]
) concat( ) concat(
["center"], [CENTER],
[for (a=concat(xs,ys,zs)) a], [for (a=concat(xs,ys,zs)) a],
in_list(type,["cube","cylinder"])? [for (a=zs, b=ys) str(a,"-",b)] : [], in_list(type,["cube","cylinder"])? [for (a=zs, b=ys) a+b] : [],
in_list(type,["cube","cylinder"])? [for (a=zs, b=xs) str(a,"-",b)] : [], in_list(type,["cube","cylinder"])? [for (a=zs, b=xs) a+b] : [],
in_list(type,["cube"])? [for (a=ys, b=xs) str(a,"-",b)] : [], in_list(type,["cube"])? [for (a=ys, b=xs) a+b] : [],
in_list(type,["cube"])? [for (a=zs, b=ys, c=xs) str(a,"-",b,"-",c)] : [] in_list(type,["cube"])? [for (a=zs, b=ys, c=xs) a+b+c] : []
); );
@ -209,10 +209,10 @@ function all_conns(type="cube") =
module connector_arrow(s=10, color=[0.333,0.333,1], flag=true) { module connector_arrow(s=10, color=[0.333,0.333,1], flag=true) {
$fn=12; $fn=12;
recolor("gray") spheroid(d=s/6) recolor("gray") spheroid(d=s/6)
recolor(color) cyl(h=s*2/3, d=s/15, align=V_UP) recolor(color) cyl(h=s*2/3, d=s/15, align=UP)
attach("top") cyl(h=s/3, d1=s/5, d2=0, align=V_UP) { attach(TOP) cyl(h=s/3, d1=s/5, d2=0, align=UP) {
if(flag) { if(flag) {
attach("bottom") recolor([1,0.5,0.5]) cuboid([s/50, s/6, s/4], align="front-top"); attach(BOTTOM) recolor([1,0.5,0.5]) cuboid([s/50, s/6, s/4], align="front-top");
} }
} }
} }
@ -240,9 +240,9 @@ module show_connectors(type="cube") {
// s = Length of the arrows. // s = Length of the arrows.
module frameref(s=15) { module frameref(s=15) {
sphere(0.001) { sphere(0.001) {
attach("right") connector_arrow(s=s, color="red", flag=false); attach(RIGHT) connector_arrow(s=s, color="red", flag=false);
attach("back") connector_arrow(s=s, color="green", flag=false); attach(BACK) connector_arrow(s=s, color="green", flag=false);
attach("top") connector_arrow(s=s, color="blue", flag=false); attach(TOP) connector_arrow(s=s, color="blue", flag=false);
} }
} }

View file

@ -289,7 +289,7 @@ module gear2d(
// scale = Scale of top of gear compared to bottom. Useful for making crown gears. // scale = Scale of top of gear compared to bottom. Useful for making crown gears.
// interior = If true, create a mask for difference()ing from something else. // interior = If true, create a mask for difference()ing from something else.
// orient = Orientation of the gear. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the gear. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the gear. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the gear. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: Spur Gear // Example: Spur Gear
// gear(mm_per_tooth=5, number_of_teeth=20, thickness=8, hole_diameter=5); // gear(mm_per_tooth=5, number_of_teeth=20, thickness=8, hole_diameter=5);
// Example: Beveled Gear // Example: Beveled Gear
@ -308,7 +308,7 @@ module gear(
slices = undef, //Number of slices to divide gear into. Useful for refining gears with `twist`. slices = undef, //Number of slices to divide gear into. Useful for refining gears with `twist`.
interior = false, interior = false,
orient = ORIENT_Z, orient = ORIENT_Z,
align = V_CENTER align = CENTER
) { ) {
p = pitch_radius(mm_per_tooth, number_of_teeth); p = pitch_radius(mm_per_tooth, number_of_teeth);
c = outer_radius(mm_per_tooth, number_of_teeth, clearance, interior); c = outer_radius(mm_per_tooth, number_of_teeth, clearance, interior);
@ -358,7 +358,7 @@ module gear(
// pressure_angle = Controls how straight or bulged the tooth sides are. In degrees. // pressure_angle = Controls how straight or bulged the tooth sides are. In degrees.
// backlash = Gap between two meshing teeth, in the direction along the circumference of the pitch circle // backlash = Gap between two meshing teeth, in the direction along the circumference of the pitch circle
// orient = Orientation of the rack. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the rack. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the rack. Use the `V_` constants from `constants.scad`. Default: `V_RIGHT`. // align = Alignment of the rack. Use the constants from `constants.scad`. Default: `RIGHT`.
// Example: // Example:
// rack(mm_per_tooth=5, number_of_teeth=10, thickness=5, height=5, pressure_angle=20); // rack(mm_per_tooth=5, number_of_teeth=10, thickness=5, height=5, pressure_angle=20);
module rack( module rack(
@ -370,7 +370,7 @@ module rack(
backlash = 0.0, //gap between two meshing teeth, in the direction along the circumference of the pitch circle backlash = 0.0, //gap between two meshing teeth, in the direction along the circumference of the pitch circle
clearance = undef, clearance = undef,
orient = ORIENT_X, orient = ORIENT_X,
align = V_RIGHT align = RIGHT
) { ) {
a = adendum(mm_per_tooth); a = adendum(mm_per_tooth);
d = dedendum(mm_per_tooth, clearance); d = dedendum(mm_per_tooth, clearance);

View file

@ -58,10 +58,10 @@ include <constants.scad>
// clearance = Extra width to clear. // clearance = Extra width to clear.
// overlap = Extra depth to clear. // overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// half_joiner_clear(orient=ORIENT_X); // half_joiner_clear(orient=ORIENT_X);
module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, align=V_CENTER) module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, align=CENTER)
{ {
dmnd_height = h*1.0; dmnd_height = h*1.0;
dmnd_width = dmnd_height*tan(a); dmnd_width = dmnd_height*tan(a);
@ -101,10 +101,10 @@ module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, orient=ORI
// guides = If true, create sliding alignment guides. // guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely. // slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// half_joiner(screwsize=3, orient=ORIENT_X); // half_joiner(screwsize=3, orient=ORIENT_X);
module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=V_CENTER) module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=CENTER)
{ {
dmnd_height = h*1.0; dmnd_height = h*1.0;
dmnd_width = dmnd_height*tan(a); dmnd_width = dmnd_height*tan(a);
@ -166,7 +166,7 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PR
} }
} }
} }
//half_joiner(screwsize=3, orient=ORIENT_Z, align=V_UP); //half_joiner(screwsize=3, orient=ORIENT_Z, align=UP);
@ -183,10 +183,10 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PR
// screwsize = Diameter of screwhole. // screwsize = Diameter of screwhole.
// guides = If true, create sliding alignment guides. // guides = If true, create sliding alignment guides.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// half_joiner2(screwsize=3, orient=ORIENT_X); // half_joiner2(screwsize=3, orient=ORIENT_X);
module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, orient=ORIENT_Y, align=V_CENTER) module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, orient=ORIENT_Y, align=CENTER)
{ {
dmnd_height = h*1.0; dmnd_height = h*1.0;
dmnd_width = dmnd_height*tan(a); dmnd_width = dmnd_height*tan(a);
@ -236,10 +236,10 @@ module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, orient
// clearance = Extra width to clear. // clearance = Extra width to clear.
// overlap = Extra depth to clear. // overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// joiner_clear(orient=ORIENT_X); // joiner_clear(orient=ORIENT_X);
module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, align=V_CENTER) module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, align=CENTER)
{ {
dmnd_height = h*0.5; dmnd_height = h*0.5;
dmnd_width = dmnd_height*tan(a); dmnd_width = dmnd_height*tan(a);
@ -268,11 +268,11 @@ module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y
// guides = If true, create sliding alignment guides. // guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely. // slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// joiner(screwsize=3, orient=ORIENT_X); // joiner(screwsize=3, orient=ORIENT_X);
// joiner(w=10, l=10, h=40, orient=ORIENT_X) cuboid([10, 10*2, 40], align=V_LEFT); // joiner(w=10, l=10, h=40, orient=ORIENT_X) cuboid([10, 10*2, 40], align=LEFT);
module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=V_CENTER) module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=CENTER)
{ {
if ($children > 0) { if ($children > 0) {
difference() { difference() {
@ -305,11 +305,11 @@ module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER
// clearance = Extra width to clear. // clearance = Extra width to clear.
// overlap = Extra depth to clear. // overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// joiner_pair_clear(spacing=50, n=2); // joiner_pair_clear(spacing=50, n=2);
// joiner_pair_clear(spacing=50, n=3); // joiner_pair_clear(spacing=50, n=3);
module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overlap=0.01, orient=ORIENT_Y, align=V_CENTER) module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overlap=0.01, orient=ORIENT_Y, align=CENTER)
{ {
dmnd_height = h*0.5; dmnd_height = h*0.5;
dmnd_width = dmnd_height*tan(a); dmnd_width = dmnd_height*tan(a);
@ -342,14 +342,14 @@ module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overla
// guides = If true, create sliding alignment guides. // guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely. // slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// joiner_pair(spacing=50, l=10, orient=ORIENT_X) cuboid([10, 50+10-0.1, 40], align=V_LEFT); // joiner_pair(spacing=50, l=10, orient=ORIENT_X) cuboid([10, 50+10-0.1, 40], align=LEFT);
// joiner_pair(spacing=50, l=10, n=2, orient=ORIENT_X); // joiner_pair(spacing=50, l=10, n=2, orient=ORIENT_X);
// joiner_pair(spacing=50, l=10, n=3, alternate=false, orient=ORIENT_X); // joiner_pair(spacing=50, l=10, n=3, alternate=false, orient=ORIENT_X);
// joiner_pair(spacing=50, l=10, n=3, alternate=true, orient=ORIENT_X); // joiner_pair(spacing=50, l=10, n=3, alternate=true, orient=ORIENT_X);
// joiner_pair(spacing=50, l=10, n=3, alternate="alt", orient=ORIENT_X); // joiner_pair(spacing=50, l=10, n=3, alternate="alt", orient=ORIENT_X);
module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=V_CENTER) module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=CENTER)
{ {
if ($children > 0) { if ($children > 0) {
difference() { difference() {
@ -390,11 +390,11 @@ module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, scr
// clearance = Extra width to clear. // clearance = Extra width to clear.
// overlap = Extra depth to clear. // overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// joiner_quad_clear(spacing1=50, spacing2=50, n=2); // joiner_quad_clear(spacing1=50, spacing2=50, n=2);
// joiner_quad_clear(spacing1=50, spacing2=50, n=3); // joiner_quad_clear(spacing1=50, spacing2=50, n=3);
module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing2=undef, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, align=V_CENTER) module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing2=undef, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, align=CENTER)
{ {
spacing1 = first_defined([spacing1, xspacing, 100]); spacing1 = first_defined([spacing1, xspacing, 100]);
spacing2 = first_defined([spacing2, yspacing, 50]); spacing2 = first_defined([spacing2, yspacing, 50]);
@ -426,14 +426,14 @@ module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing
// guides = If true, create sliding alignment guides. // guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely. // slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// joiner_quad(spacing1=50, spacing2=50, l=10, orient=ORIENT_X) cuboid([50, 50+10-0.1, 40]); // joiner_quad(spacing1=50, spacing2=50, l=10, orient=ORIENT_X) cuboid([50, 50+10-0.1, 40]);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=2, orient=ORIENT_X); // joiner_quad(spacing1=50, spacing2=50, l=10, n=2, orient=ORIENT_X);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=false, orient=ORIENT_X); // joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=false, orient=ORIENT_X);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=true, orient=ORIENT_X); // joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=true, orient=ORIENT_X);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate="alt", orient=ORIENT_X); // joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate="alt", orient=ORIENT_X);
module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=undef, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=V_CENTER) module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=undef, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, align=CENTER)
{ {
spacing1 = first_defined([spacing1, xspacing, 100]); spacing1 = first_defined([spacing1, xspacing, 100]);
spacing2 = first_defined([spacing2, yspacing, 50]); spacing2 = first_defined([spacing2, yspacing, 50]);

View file

@ -106,10 +106,10 @@ function get_lmXuu_bearing_length(size) = lookup(size, [
// gap = Gap in clamp. (Default: 5) // gap = Gap in clamp. (Default: 5)
// screwsize = Size of screw to use to tighten clamp. (Default: 3) // screwsize = Size of screw to use to tighten clamp. (Default: 3)
// orient = Orientation of the housing. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the housing. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the housing by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_UP` // align = Alignment of the housing by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `UP`
// Example: // Example:
// linear_bearing_housing(d=19, l=29, wall=2, tab=6, screwsize=2.5); // linear_bearing_housing(d=19, l=29, wall=2, tab=6, screwsize=2.5);
module linear_bearing_housing(d=15, l=24, tab=7, gap=5, wall=3, tabwall=5, screwsize=3, orient=ORIENT_X, align=V_UP) module linear_bearing_housing(d=15, l=24, tab=7, gap=5, wall=3, tabwall=5, screwsize=3, orient=ORIENT_X, align=UP)
{ {
od = d+2*wall; od = d+2*wall;
ogap = gap+2*tabwall; ogap = gap+2*tabwall;
@ -146,10 +146,10 @@ module linear_bearing_housing(d=15, l=24, tab=7, gap=5, wall=3, tabwall=5, screw
// gap = Gap in clamp. Default: 5 // gap = Gap in clamp. Default: 5
// screwsize = Size of screw to use to tighten clamp. Default: 3 // screwsize = Size of screw to use to tighten clamp. Default: 3
// orient = Orientation of the housing. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the housing. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the housing by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `V_UP` // align = Alignment of the housing by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `UP`
// Example: // Example:
// lmXuu_housing(size=10, wall=2, tab=6, screwsize=2.5); // lmXuu_housing(size=10, wall=2, tab=6, screwsize=2.5);
module lmXuu_housing(size=8, tab=7, gap=5, wall=3, tabwall=5, screwsize=3, orient=ORIENT_X, align=V_UP) module lmXuu_housing(size=8, tab=7, gap=5, wall=3, tabwall=5, screwsize=3, orient=ORIENT_X, align=UP)
{ {
d = get_lmXuu_bearing_diam(size); d = get_lmXuu_bearing_diam(size);
l = get_lmXuu_bearing_length(size); l = get_lmXuu_bearing_length(size);

View file

@ -62,7 +62,7 @@ include <constants.scad>
// d1 = Bottom diameter of cone that wedge is created from. (optional) // d1 = Bottom diameter of cone that wedge is created from. (optional)
// d2 = Upper diameter of cone that wedge is created from. (optional) // d2 = Upper diameter of cone that wedge is created from. (optional)
// orient = Orientation of the pie slice. Use the ORIENT_ constants from constants.h. Default: ORIENT_Z. // orient = Orientation of the pie slice. Use the ORIENT_ constants from constants.h. Default: ORIENT_Z.
// align = Alignment of the pie slice. Use the V_ constants from constants.h. Default: V_CENTER. // align = Alignment of the pie slice. Use the constants from constants.h. Default: CENTER.
// center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`. // center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`.
// Example(FR): // Example(FR):
// angle_pie_mask(ang=30, d=100, l=20); // angle_pie_mask(ang=30, d=100, l=20);
@ -70,14 +70,14 @@ module angle_pie_mask(
ang=45, l=undef, ang=45, l=undef,
r=undef, r1=undef, r2=undef, r=undef, r1=undef, r2=undef,
d=undef, d1=undef, d2=undef, d=undef, d1=undef, d2=undef,
orient=ORIENT_Z, align=V_CENTER, orient=ORIENT_Z, align=CENTER,
h=undef, center=undef h=undef, center=undef
) { ) {
l = first_defined([l, h, 1]); l = first_defined([l, h, 1]);
r1 = get_radius(r1, r, d1, d, 10); r1 = get_radius(r1, r, d1, d, 10);
r2 = get_radius(r2, r, d2, d, 10); r2 = get_radius(r2, r, d2, d, 10);
orient_and_align([2*r1, 2*r1, l], orient, align, center=center) { orient_and_align([2*r1, 2*r1, l], orient, align, center=center) {
pie_slice(ang=ang, l=l+0.1, r1=r1, r2=r2, align=V_CENTER); pie_slice(ang=ang, l=l+0.1, r1=r1, r2=r2, align=CENTER);
} }
} }
@ -120,7 +120,7 @@ module angle_pie_mask(
// overage = The extra thickness of the mask. Default: `10`. // overage = The extra thickness of the mask. Default: `10`.
// ends_only = If true, only mask the ends and not around the middle of the cylinder. // ends_only = If true, only mask the ends and not around the middle of the cylinder.
// orient = Orientation. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the region. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the region. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// difference() { // difference() {
// cylinder(h=100, r1=60, r2=30, center=true); // cylinder(h=100, r1=60, r2=30, center=true);
@ -139,7 +139,7 @@ module cylinder_mask(
fillet=undef, fillet1=undef, fillet2=undef, fillet=undef, fillet1=undef, fillet2=undef,
circum=false, from_end=false, circum=false, from_end=false,
overage=10, ends_only=false, overage=10, ends_only=false,
orient=ORIENT_Z, align=V_CENTER orient=ORIENT_Z, align=CENTER
) { ) {
r1 = get_radius(r=r, d=d, r1=r1, d1=d1, dflt=1); r1 = get_radius(r=r, d=d, r1=r1, d1=d1, dflt=1);
r2 = get_radius(r=r, d=d, r1=r2, d1=d2, dflt=1); r2 = get_radius(r=r, d=d, r1=r2, d1=d2, dflt=1);
@ -195,14 +195,14 @@ module cylinder_mask(
// l = Length of mask. // l = Length of mask.
// chamfer = Size of chamfer // chamfer = Size of chamfer
// orient = Orientation of the mask. Use the `ORIENT_` constants from `constants.h`. Default: vertical. // orient = Orientation of the mask. Use the `ORIENT_` constants from `constants.h`. Default: vertical.
// align = Alignment of the mask. Use the `V_` constants from `constants.h`. Default: centered. // align = Alignment of the mask. Use the constants from `constants.h`. Default: centered.
// center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`. // center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`.
// Example: // Example:
// difference() { // difference() {
// cube(50); // cube(50);
// #chamfer_mask(l=50, chamfer=10, orient=ORIENT_X, align=V_RIGHT); // #chamfer_mask(l=50, chamfer=10, orient=ORIENT_X, align=RIGHT);
// } // }
module chamfer_mask(l=1, chamfer=1, orient=ORIENT_Z, align=V_CENTER, center=undef) { module chamfer_mask(l=1, chamfer=1, orient=ORIENT_Z, align=CENTER, center=undef) {
orient_and_align([chamfer, chamfer, l], orient, align, center=center) { orient_and_align([chamfer, chamfer, l], orient, align, center=center) {
cylinder(d=chamfer*2, h=l+0.1, center=true, $fn=4); cylinder(d=chamfer*2, h=l+0.1, center=true, $fn=4);
} }
@ -219,13 +219,13 @@ module chamfer_mask(l=1, chamfer=1, orient=ORIENT_Z, align=V_CENTER, center=unde
// Arguments: // Arguments:
// l = Height of mask // l = Height of mask
// chamfer = size of chamfer // chamfer = size of chamfer
// align = Alignment of the cylinder. Use the V_ constants from constants.h. Default: centered. // align = Alignment of the cylinder. Use the constants from constants.h. Default: centered.
// Example: // Example:
// difference() { // difference() {
// left(40) cube(80); // left(40) cube(80);
// #chamfer_mask_x(l=80, chamfer=20); // #chamfer_mask_x(l=80, chamfer=20);
// } // }
module chamfer_mask_x(l=1.0, chamfer=1.0, align=V_CENTER) { module chamfer_mask_x(l=1.0, chamfer=1.0, align=CENTER) {
chamfer_mask(l=l, chamfer=chamfer, orient=ORIENT_X, align=align); chamfer_mask(l=l, chamfer=chamfer, orient=ORIENT_X, align=align);
} }
@ -240,13 +240,13 @@ module chamfer_mask_x(l=1.0, chamfer=1.0, align=V_CENTER) {
// Arguments: // Arguments:
// l = Height of mask // l = Height of mask
// chamfer = size of chamfer // chamfer = size of chamfer
// align = Alignment of the cylinder. Use the V_ constants from constants.h. Default: centered. // align = Alignment of the cylinder. Use the constants from constants.h. Default: centered.
// Example: // Example:
// difference() { // difference() {
// fwd(40) cube(80); // fwd(40) cube(80);
// right(80) #chamfer_mask_y(l=80, chamfer=20); // right(80) #chamfer_mask_y(l=80, chamfer=20);
// } // }
module chamfer_mask_y(l=1.0, chamfer=1.0, align=V_CENTER) { module chamfer_mask_y(l=1.0, chamfer=1.0, align=CENTER) {
chamfer_mask(l=l, chamfer=chamfer, orient=ORIENT_Y, align=align); chamfer_mask(l=l, chamfer=chamfer, orient=ORIENT_Y, align=align);
} }
@ -261,13 +261,13 @@ module chamfer_mask_y(l=1.0, chamfer=1.0, align=V_CENTER) {
// Arguments: // Arguments:
// l = Height of mask // l = Height of mask
// chamfer = size of chamfer // chamfer = size of chamfer
// align = Alignment of the cylinder. Use the V_ constants from constants.h. Default: centered. // align = Alignment of the cylinder. Use the constants from constants.h. Default: centered.
// Example: // Example:
// difference() { // difference() {
// down(40) cube(80); // down(40) cube(80);
// #chamfer_mask_z(l=80, chamfer=20); // #chamfer_mask_z(l=80, chamfer=20);
// } // }
module chamfer_mask_z(l=1.0, chamfer=1.0, align=V_CENTER) { module chamfer_mask_z(l=1.0, chamfer=1.0, align=CENTER) {
chamfer_mask(l=l, chamfer=chamfer, orient=ORIENT_Z, align=align); chamfer_mask(l=l, chamfer=chamfer, orient=ORIENT_Z, align=align);
} }
@ -332,7 +332,7 @@ module chamfer(chamfer=1, size=[1,1,1], edges=EDGES_ALL)
module chamfer_cylinder_mask(r=1.0, d=undef, chamfer=0.25, ang=45, from_end=false, orient=ORIENT_Z) module chamfer_cylinder_mask(r=1.0, d=undef, chamfer=0.25, ang=45, from_end=false, orient=ORIENT_Z)
{ {
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
rot(orient) cylinder_mask(l=chamfer*3, r=r, chamfer2=chamfer, chamfang2=ang, from_end=from_end, ends_only=true, align=V_DOWN); rot(orient) cylinder_mask(l=chamfer*3, r=r, chamfer2=chamfer, chamfang2=ang, from_end=from_end, ends_only=true, align=DOWN);
} }
@ -388,14 +388,14 @@ module chamfer_hole_mask(r=undef, d=undef, chamfer=0.25, ang=45, from_end=false,
// l = Length of mask. // l = Length of mask.
// r = Radius of the fillet. // r = Radius of the fillet.
// orient = Orientation of the mask. Use the `ORIENT_` constants from `constants.h`. Default: vertical. // orient = Orientation of the mask. Use the `ORIENT_` constants from `constants.h`. Default: vertical.
// align = Alignment of the mask. Use the `V_` constants from `constants.h`. Default: centered. // align = Alignment of the mask. Use the constants from `constants.h`. Default: centered.
// center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`. // center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`.
// Example: // Example:
// difference() { // difference() {
// cube(size=100, center=false); // cube(size=100, center=false);
// #fillet_mask(l=100, r=25, orient=ORIENT_Z, align=V_UP); // #fillet_mask(l=100, r=25, orient=ORIENT_Z, align=UP);
// } // }
module fillet_mask(l=undef, r=1.0, orient=ORIENT_Z, align=V_CENTER, h=undef, center=undef) module fillet_mask(l=undef, r=1.0, orient=ORIENT_Z, align=CENTER, h=undef, center=undef)
{ {
l = first_defined([l, h, 1]); l = first_defined([l, h, 1]);
sides = quantup(segs(r),4); sides = quantup(segs(r),4);
@ -421,14 +421,14 @@ module fillet_mask(l=undef, r=1.0, orient=ORIENT_Z, align=V_CENTER, h=undef, cen
// Arguments: // Arguments:
// l = Length of mask. // l = Length of mask.
// r = Radius of the fillet. // r = Radius of the fillet.
// align = Alignment of the mask. Use the `V_` constants from `constants.h`. Default: centered. // align = Alignment of the mask. Use the constants from `constants.h`. Default: centered.
// center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`. // center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`.
// Example: // Example:
// difference() { // difference() {
// cube(size=100, center=false); // cube(size=100, center=false);
// #fillet_mask_x(l=100, r=25, align=V_RIGHT); // #fillet_mask_x(l=100, r=25, align=RIGHT);
// } // }
module fillet_mask_x(l=1.0, r=1.0, align=V_CENTER) fillet_mask(l=l, r=r, orient=ORIENT_X, align=align); module fillet_mask_x(l=1.0, r=1.0, align=CENTER) fillet_mask(l=l, r=r, orient=ORIENT_X, align=align);
// Module: fillet_mask_y() // Module: fillet_mask_y()
@ -442,14 +442,14 @@ module fillet_mask_x(l=1.0, r=1.0, align=V_CENTER) fillet_mask(l=l, r=r, orient=
// Arguments: // Arguments:
// l = Length of mask. // l = Length of mask.
// r = Radius of the fillet. // r = Radius of the fillet.
// align = Alignment of the mask. Use the `V_` constants from `constants.h`. Default: centered. // align = Alignment of the mask. Use the constants from `constants.h`. Default: centered.
// center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`. // center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`.
// Example: // Example:
// difference() { // difference() {
// cube(size=100, center=false); // cube(size=100, center=false);
// right(100) #fillet_mask_y(l=100, r=25, align=V_BACK); // right(100) #fillet_mask_y(l=100, r=25, align=BACK);
// } // }
module fillet_mask_y(l=1.0, r=1.0, align=V_CENTER) fillet_mask(l=l, r=r, orient=ORIENT_Y, align=align); module fillet_mask_y(l=1.0, r=1.0, align=CENTER) fillet_mask(l=l, r=r, orient=ORIENT_Y, align=align);
// Module: fillet_mask_z() // Module: fillet_mask_z()
@ -463,14 +463,14 @@ module fillet_mask_y(l=1.0, r=1.0, align=V_CENTER) fillet_mask(l=l, r=r, orient=
// Arguments: // Arguments:
// l = Length of mask. // l = Length of mask.
// r = Radius of the fillet. // r = Radius of the fillet.
// align = Alignment of the mask. Use the `V_` constants from `constants.h`. Default: centered. // align = Alignment of the mask. Use the constants from `constants.h`. Default: centered.
// center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`. // center = If true, centers vertically. If false, lift up to sit on top of the XY plane. Overrides `align`.
// Example: // Example:
// difference() { // difference() {
// cube(size=100, center=false); // cube(size=100, center=false);
// #fillet_mask_z(l=100, r=25, align=V_UP); // #fillet_mask_z(l=100, r=25, align=UP);
// } // }
module fillet_mask_z(l=1.0, r=1.0, align=V_CENTER) fillet_mask(l=l, r=r, orient=ORIENT_Z, align=align); module fillet_mask_z(l=1.0, r=1.0, align=CENTER) fillet_mask(l=l, r=r, orient=ORIENT_Z, align=align);
// Module: fillet() // Module: fillet()
@ -646,7 +646,7 @@ module fillet_cylinder_mask(r=1.0, fillet=0.25, xtilt=0, ytilt=0)
{ {
skew_xz(za=xtilt) { skew_xz(za=xtilt) {
skew_yz(za=ytilt) { skew_yz(za=ytilt) {
cylinder_mask(l=fillet*3, r=r, fillet2=fillet, overage=fillet+2*r*sin(max(xtilt,ytilt)), ends_only=true, align=V_DOWN); cylinder_mask(l=fillet*3, r=r, fillet2=fillet, overage=fillet+2*r*sin(max(xtilt,ytilt)), ends_only=true, align=DOWN);
} }
} }
} }

View file

@ -897,8 +897,8 @@ function vector_axis(v1,v2) =
v1 = point3d(v1/norm(v1)), v1 = point3d(v1/norm(v1)),
v2 = point3d(v2/norm(v2)), v2 = point3d(v2/norm(v2)),
v3 = (norm(v1-v2) > eps && norm(v1+v2) > eps)? v2 : v3 = (norm(v1-v2) > eps && norm(v1+v2) > eps)? v2 :
(norm(vabs(v2)-V_UP) > eps)? V_UP : (norm(vabs(v2)-UP) > eps)? UP :
V_RIGHT RIGHT
) normalize(cross(v1,v3)); ) normalize(cross(v1,v3));

View file

@ -403,7 +403,7 @@ function get_metric_nut_thickness(size) = lookup(size, [
// headlen = length of the screw head. // headlen = length of the screw head.
// countersunk = If true, center from cap's top instead of it's bottom. // countersunk = If true, center from cap's top instead of it's bottom.
// orient = Orientation of the screw. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the screw. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the screw. Use the `V_` constants from `constants.scad` or `"sunken"`, or `"base"`. Default: `"base"`. // align = Alignment of the screw. Use the constants from `constants.scad` or `"sunken"`, or `"base"`. Default: `"base"`.
// Examples: // Examples:
// screw(screwsize=3,screwlen=10,headsize=6,headlen=3,countersunk=true); // screw(screwsize=3,screwlen=10,headsize=6,headlen=3,countersunk=true);
// screw(screwsize=3,screwlen=10,headsize=6,headlen=3, align="base"); // screw(screwsize=3,screwlen=10,headsize=6,headlen=3, align="base");
@ -418,7 +418,7 @@ module screw(
align="base" align="base"
) { ) {
sides = max(12, segs(screwsize/2)); sides = max(12, segs(screwsize/2));
algn = countersunk? ALIGN_NEG : align; algn = countersunk? DOWN : align;
alignments = [ alignments = [
["base", [0,0,-headlen/2+screwlen/2]], ["base", [0,0,-headlen/2+screwlen/2]],
["sunken", [0,0,(headlen+screwlen)/2-0.01]] ["sunken", [0,0,(headlen+screwlen)/2-0.01]]
@ -453,7 +453,7 @@ module screw(
// phillips = If given, the size of the phillips drive hole to add. (ie: "#1", "#2", or "#3") // phillips = If given, the size of the phillips drive hole to add. (ie: "#1", "#2", or "#3")
// torx = If given, the size of the torx drive hole to add. (ie: 10, 20, 30, etc.) // torx = If given, the size of the torx drive hole to add. (ie: 10, 20, 30, etc.)
// orient = Orientation of the bolt. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the bolt. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the bolt. Use the `V_` constants from `constants.scad` or `"sunken"`, `"base"`, or `"shank"`. Default: `"base"`. // align = Alignment of the bolt. Use the constants from `constants.scad` or `"sunken"`, `"base"`, or `"shank"`. Default: `"base"`.
// Example: Bolt Head Types // Example: Bolt Head Types
// ydistribute(40) { // ydistribute(40) {
// xdistribute(30) { // xdistribute(30) {
@ -566,7 +566,7 @@ module metric_bolt(
} }
} }
} else if (headtype == "pan") { } else if (headtype == "pan") {
cyl(l=H*0.75, d=D, fillet2=H*0.75/2, align=V_UP); cyl(l=H*0.75, d=D, fillet2=H*0.75/2, align=UP);
} else if (headtype == "round") { } else if (headtype == "round") {
top_half() zscale(H*0.75/D*2) sphere(d=D); top_half() zscale(H*0.75/D*2) sphere(d=D);
} else if (headtype == "button") { } else if (headtype == "button") {
@ -643,7 +643,7 @@ module metric_bolt(
// flange = radius of flange beyond the head. Default = 0 (no flange) // flange = radius of flange beyond the head. Default = 0 (no flange)
// details = true if model should be rendered with extra details. (Default: false) // details = true if model should be rendered with extra details. (Default: false)
// orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the nut. Use the `V_` constants from `constants.scad`. Default: `V_UP`. // align = Alignment of the nut. Use the constants from `constants.scad`. Default: `UP`.
// center = If true, centers the nut at the origin. If false, sits on top of XY plane. Overrides `align` if given. // center = If true, centers the nut at the origin. If false, sits on top of XY plane. Overrides `align` if given.
// Example: No details, No Hole. Useful for a mask. // Example: No details, No Hole. Useful for a mask.
// metric_nut(size=10, hole=false); // metric_nut(size=10, hole=false);
@ -665,7 +665,7 @@ module metric_nut(
flange=0, flange=0,
center=undef, center=undef,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_UP align=UP
) { ) {
H = get_metric_nut_thickness(size); H = get_metric_nut_thickness(size);
D = get_metric_nut_size(size); D = get_metric_nut_size(size);

View file

@ -134,10 +134,10 @@ function nema_motor_screw_depth(size) = lookup(size, [
// shaft = Shaft diameter. Default: 5mm // shaft = Shaft diameter. Default: 5mm
// shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 20mm // shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 20mm
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_DOWN`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `DOWN`.
// Example: // Example:
// nema11_stepper(); // nema11_stepper();
module nema11_stepper(h=24, shaft=5, shaft_len=20, orient=ORIENT_Z, align=V_DOWN) module nema11_stepper(h=24, shaft=5, shaft_len=20, orient=ORIENT_Z, align=DOWN)
{ {
size = 11; size = 11;
motor_width = nema_motor_width(size); motor_width = nema_motor_width(size);
@ -147,10 +147,10 @@ module nema11_stepper(h=24, shaft=5, shaft_len=20, orient=ORIENT_Z, align=V_DOWN
screw_size = nema_motor_screw_size(size); screw_size = nema_motor_screw_size(size);
screw_depth = nema_motor_screw_depth(size); screw_depth = nema_motor_screw_depth(size);
orient_and_align([motor_width, motor_width, h], orient, align, orig_align=V_DOWN) { orient_and_align([motor_width, motor_width, h], orient, align, orig_align=DOWN) {
difference() { difference() {
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cuboid(size=[motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=V_DOWN); cuboid(size=[motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=DOWN);
color("silver") color("silver")
xspread(screw_spacing) xspread(screw_spacing)
yspread(screw_spacing) yspread(screw_spacing)
@ -176,10 +176,10 @@ module nema11_stepper(h=24, shaft=5, shaft_len=20, orient=ORIENT_Z, align=V_DOWN
// shaft = Shaft diameter. Default: 5mm // shaft = Shaft diameter. Default: 5mm
// shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 24mm // shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 24mm
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_DOWN`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `DOWN`.
// Example: // Example:
// nema14_stepper(); // nema14_stepper();
module nema14_stepper(h=24, shaft=5, shaft_len=24, orient=ORIENT_Z, align=V_DOWN) module nema14_stepper(h=24, shaft=5, shaft_len=24, orient=ORIENT_Z, align=DOWN)
{ {
size = 14; size = 14;
motor_width = nema_motor_width(size); motor_width = nema_motor_width(size);
@ -189,10 +189,10 @@ module nema14_stepper(h=24, shaft=5, shaft_len=24, orient=ORIENT_Z, align=V_DOWN
screw_size = nema_motor_screw_size(size); screw_size = nema_motor_screw_size(size);
screw_depth = nema_motor_screw_depth(size); screw_depth = nema_motor_screw_depth(size);
orient_and_align([motor_width, motor_width, h], orient, align, orig_align=V_DOWN) { orient_and_align([motor_width, motor_width, h], orient, align, orig_align=DOWN) {
difference() { difference() {
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cuboid(size=[motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=V_DOWN); cuboid(size=[motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=DOWN);
color("silver") color("silver")
xspread(screw_spacing) xspread(screw_spacing)
yspread(screw_spacing) yspread(screw_spacing)
@ -205,7 +205,7 @@ module nema14_stepper(h=24, shaft=5, shaft_len=24, orient=ORIENT_Z, align=V_DOWN
} }
} }
color("silver") color("silver")
cyl(h=shaft_len, d=shaft, align=V_UP, $fn=max(12,segs(shaft/2))); cyl(h=shaft_len, d=shaft, align=UP, $fn=max(12,segs(shaft/2)));
} }
} }
@ -218,10 +218,10 @@ module nema14_stepper(h=24, shaft=5, shaft_len=24, orient=ORIENT_Z, align=V_DOWN
// shaft = Shaft diameter. Default: 5mm // shaft = Shaft diameter. Default: 5mm
// shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 20mm // shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 20mm
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_DOWN`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `DOWN`.
// Example: // Example:
// nema17_stepper(); // nema17_stepper();
module nema17_stepper(h=34, shaft=5, shaft_len=20, orient=ORIENT_Z, align=V_DOWN) module nema17_stepper(h=34, shaft=5, shaft_len=20, orient=ORIENT_Z, align=DOWN)
{ {
size = 17; size = 17;
motor_width = nema_motor_width(size); motor_width = nema_motor_width(size);
@ -231,10 +231,10 @@ module nema17_stepper(h=34, shaft=5, shaft_len=20, orient=ORIENT_Z, align=V_DOWN
screw_size = nema_motor_screw_size(size); screw_size = nema_motor_screw_size(size);
screw_depth = nema_motor_screw_depth(size); screw_depth = nema_motor_screw_depth(size);
orient_and_align([motor_width, motor_width, h], orient, align, orig_align=V_DOWN) { orient_and_align([motor_width, motor_width, h], orient, align, orig_align=DOWN) {
difference() { difference() {
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cuboid([motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=V_DOWN); cuboid([motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=DOWN);
color("silver") color("silver")
xspread(screw_spacing) xspread(screw_spacing)
yspread(screw_spacing) yspread(screw_spacing)
@ -278,10 +278,10 @@ module nema17_stepper(h=34, shaft=5, shaft_len=20, orient=ORIENT_Z, align=V_DOWN
// shaft = Shaft diameter. Default: 6.35mm // shaft = Shaft diameter. Default: 6.35mm
// shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 25mm // shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 25mm
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_DOWN`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `DOWN`.
// Example: // Example:
// nema23_stepper(); // nema23_stepper();
module nema23_stepper(h=50, shaft=6.35, shaft_len=25, orient=ORIENT_Z, align=V_DOWN) module nema23_stepper(h=50, shaft=6.35, shaft_len=25, orient=ORIENT_Z, align=DOWN)
{ {
size = 23; size = 23;
motor_width = nema_motor_width(size); motor_width = nema_motor_width(size);
@ -292,11 +292,11 @@ module nema23_stepper(h=50, shaft=6.35, shaft_len=25, orient=ORIENT_Z, align=V_D
screw_depth = nema_motor_screw_depth(size); screw_depth = nema_motor_screw_depth(size);
screw_inset = motor_width - screw_spacing + 1; screw_inset = motor_width - screw_spacing + 1;
orient_and_align([motor_width, motor_width, h], orient, align, orig_align=V_DOWN) { orient_and_align([motor_width, motor_width, h], orient, align, orig_align=DOWN) {
difference() { difference() {
union() { union() {
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cuboid([motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=V_DOWN); cuboid([motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=DOWN);
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cylinder(h=plinth_height, d=plinth_diam); cylinder(h=plinth_height, d=plinth_diam);
color("silver") color("silver")
@ -306,7 +306,7 @@ module nema23_stepper(h=50, shaft=6.35, shaft_len=25, orient=ORIENT_Z, align=V_D
xspread(screw_spacing) { xspread(screw_spacing) {
yspread(screw_spacing) { yspread(screw_spacing) {
cyl(d=screw_size, h=screw_depth*3, $fn=max(12,segs(screw_size/2))); cyl(d=screw_size, h=screw_depth*3, $fn=max(12,segs(screw_size/2)));
down(screw_depth) cuboid([screw_inset, screw_inset, h], align=V_DOWN); down(screw_depth) cuboid([screw_inset, screw_inset, h], align=DOWN);
} }
} }
} }
@ -323,10 +323,10 @@ module nema23_stepper(h=50, shaft=6.35, shaft_len=25, orient=ORIENT_Z, align=V_D
// shaft = Shaft diameter. Default: 12.7mm // shaft = Shaft diameter. Default: 12.7mm
// shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 32mm // shaft_len = Length of shaft protruding out the top of the stepper motor. Default: 32mm
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_DOWN`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `DOWN`.
// Example: // Example:
// nema34_stepper(); // nema34_stepper();
module nema34_stepper(h=75, shaft=12.7, shaft_len=32, orient=ORIENT_Z, align=V_DOWN) module nema34_stepper(h=75, shaft=12.7, shaft_len=32, orient=ORIENT_Z, align=DOWN)
{ {
size = 34; size = 34;
motor_width = nema_motor_width(size); motor_width = nema_motor_width(size);
@ -337,11 +337,11 @@ module nema34_stepper(h=75, shaft=12.7, shaft_len=32, orient=ORIENT_Z, align=V_D
screw_depth = nema_motor_screw_depth(size); screw_depth = nema_motor_screw_depth(size);
screw_inset = motor_width - screw_spacing + 1; screw_inset = motor_width - screw_spacing + 1;
orient_and_align([motor_width, motor_width, h], orient, align, orig_align=V_DOWN) { orient_and_align([motor_width, motor_width, h], orient, align, orig_align=DOWN) {
difference() { difference() {
union() { union() {
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cuboid(size=[motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=V_DOWN); cuboid(size=[motor_width, motor_width, h], chamfer=2, edges=EDGES_Z_ALL, align=DOWN);
color([0.4, 0.4, 0.4]) color([0.4, 0.4, 0.4])
cylinder(h=plinth_height, d=plinth_diam); cylinder(h=plinth_height, d=plinth_diam);
color("silver") color("silver")
@ -373,14 +373,14 @@ module nema34_stepper(h=75, shaft=12.7, shaft_len=32, orient=ORIENT_Z, align=V_D
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema_mount_holes(size=14, depth=5, l=5); // nema_mount_holes(size=14, depth=5, l=5);
// Example: // Example:
// nema_mount_holes(size=17, depth=5, l=5); // nema_mount_holes(size=17, depth=5, l=5);
// Example: // Example:
// nema_mount_holes(size=17, depth=5, l=0); // nema_mount_holes(size=17, depth=5, l=0);
module nema_mount_holes(size=17, depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema_mount_holes(size=17, depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
motor_width = nema_motor_width(size); motor_width = nema_motor_width(size);
plinth_diam = nema_motor_plinth_diam(size)+slop; plinth_diam = nema_motor_plinth_diam(size)+slop;
@ -422,12 +422,12 @@ module nema_mount_holes(size=17, depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema11_mount_holes(depth=5, l=5); // nema11_mount_holes(depth=5, l=5);
// Example: // Example:
// nema11_mount_holes(depth=5, l=0); // nema11_mount_holes(depth=5, l=0);
module nema11_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema11_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
nema_mount_holes(size=11, depth=depth, l=l, slop=slop, orient=orient, align=align); nema_mount_holes(size=11, depth=depth, l=l, slop=slop, orient=orient, align=align);
} }
@ -441,12 +441,12 @@ module nema11_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, alig
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema14_mount_holes(depth=5, l=5); // nema14_mount_holes(depth=5, l=5);
// Example: // Example:
// nema14_mount_holes(depth=5, l=0); // nema14_mount_holes(depth=5, l=0);
module nema14_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema14_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
nema_mount_holes(size=14, depth=depth, l=l, slop=slop, orient=orient, align=align); nema_mount_holes(size=14, depth=depth, l=l, slop=slop, orient=orient, align=align);
} }
@ -460,12 +460,12 @@ module nema14_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, alig
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema17_mount_holes(depth=5, l=5); // nema17_mount_holes(depth=5, l=5);
// Example: // Example:
// nema17_mount_holes(depth=5, l=0); // nema17_mount_holes(depth=5, l=0);
module nema17_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema17_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
nema_mount_holes(size=17, depth=depth, l=l, slop=slop, orient=orient, align=align); nema_mount_holes(size=17, depth=depth, l=l, slop=slop, orient=orient, align=align);
} }
@ -479,12 +479,12 @@ module nema17_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, alig
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema23_mount_holes(depth=5, l=5); // nema23_mount_holes(depth=5, l=5);
// Example: // Example:
// nema23_mount_holes(depth=5, l=0); // nema23_mount_holes(depth=5, l=0);
module nema23_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema23_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
nema_mount_holes(size=23, depth=depth, l=l, slop=slop, orient=orient, align=align); nema_mount_holes(size=23, depth=depth, l=l, slop=slop, orient=orient, align=align);
} }
@ -498,12 +498,12 @@ module nema23_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, alig
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema34_mount_holes(depth=5, l=5); // nema34_mount_holes(depth=5, l=5);
// Example: // Example:
// nema34_mount_holes(depth=5, l=0); // nema34_mount_holes(depth=5, l=0);
module nema34_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema34_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
nema_mount_holes(size=34, depth=depth, l=l, slop=slop, orient=orient, align=align); nema_mount_holes(size=34, depth=depth, l=l, slop=slop, orient=orient, align=align);
} }
@ -517,12 +517,12 @@ module nema34_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, alig
// l = The length of the slots, for making an adjustable motor mount. Default: 5 // l = The length of the slots, for making an adjustable motor mount. Default: 5
// slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP` // slop = The printer-specific slop value to make parts fit just right. Default: `PRINTER_SLOP`
// orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the stepper. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the stepper. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the stepper. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// nema34_mount_holes(depth=5, l=5); // nema34_mount_holes(depth=5, l=5);
// Example: // Example:
// nema34_mount_holes(depth=5, l=0); // nema34_mount_holes(depth=5, l=0);
module nema34_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=V_CENTER) module nema34_mount_holes(depth=5, l=5, slop=PRINTER_SLOP, orient=ORIENT_Z, align=CENTER)
{ {
nema_mount_holes(size=34, depth=depth, l=l, slop=slop, orient=orient, align=align); nema_mount_holes(size=34, depth=depth, l=l, slop=slop, orient=orient, align=align);
} }

View file

@ -235,7 +235,7 @@ module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slic
// Example: // Example:
// extrude_2d_hollow(wall=2, height=100, twist=90, slices=50) // extrude_2d_hollow(wall=2, height=100, twist=90, slices=50)
// circle(r=40, $fn=6); // circle(r=40, $fn=6);
module extrude_2d_hollow(wall=2, height=50, twist=90, slices=60, center=undef, orient=ORIENT_Z, align=V_UP) module extrude_2d_hollow(wall=2, height=50, twist=90, slices=60, center=undef, orient=ORIENT_Z, align=UP)
{ {
orient_and_align([0,0,height], orient, align, center) { orient_and_align([0,0,height], orient, align, center) {
linear_extrude(height=height, twist=twist, slices=slices, center=true) { linear_extrude(height=height, twist=twist, slices=slices, center=true) {
@ -262,7 +262,7 @@ module extrude_2d_hollow(wall=2, height=50, twist=90, slices=60, center=undef, o
// Example: // Example:
// poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]]; // poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]];
// extrude_2dpath_along_spiral(poly, h=200, r=50, twist=1080, $fn=36); // extrude_2dpath_along_spiral(poly, h=200, r=50, twist=1080, $fn=36);
module extrude_2dpath_along_spiral(polyline, h, r, twist=360, center=undef, orient=ORIENT_Z, align=V_CENTER) { module extrude_2dpath_along_spiral(polyline, h, r, twist=360, center=undef, orient=ORIENT_Z, align=CENTER) {
pline_count = len(polyline); pline_count = len(polyline);
steps = ceil(segs(r)*(twist/360)); steps = ceil(segs(r)*(twist/360));

View file

@ -58,7 +58,7 @@ include <compat.scad>
// phillips_drive(size="#2", shaft=6, l=20); // phillips_drive(size="#2", shaft=6, l=20);
// phillips_drive(size="#3", shaft=6, l=20); // phillips_drive(size="#3", shaft=6, l=20);
// } // }
module phillips_drive(size="#2", shaft=6, l=20, orient=ORIENT_Z, align=V_UP) { module phillips_drive(size="#2", shaft=6, l=20, orient=ORIENT_Z, align=UP) {
// These are my best guess reverse-engineered measurements of // These are my best guess reverse-engineered measurements of
// the tip diameters of various phillips screwdriver sizes. // the tip diameters of various phillips screwdriver sizes.
ang = 11; ang = 11;

View file

@ -55,17 +55,17 @@ use <math.scad>
// //
// Arguments: // Arguments:
// size = The size of the cube. // size = The size of the cube.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_CENTER` // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `CENTER`
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=V_UP+V_BACK+V_RIGHT`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP+BACK+RIGHT`.
// //
// Example: Simple regular cube. // Example: Simple regular cube.
// cube(40); // cube(40);
// Example: Rectangular cube, with given X, Y, and Z sizes. // Example: Rectangular cube, with given X, Y, and Z sizes.
// cuboid([20,40,50]); // cuboid([20,40,50]);
module cube(size, center=undef, align=V_ALLPOS) module cube(size, center=undef, align=ALLPOS)
{ {
size = scalar_vec3(size); size = scalar_vec3(size);
orient_and_align(size, ORIENT_Z, align, center, noncentered=V_ALLPOS, chain=true) { orient_and_align(size, ORIENT_Z, align, center, noncentered=ALLPOS, chain=true) {
linear_extrude(height=size.z, convexity=2, center=true) { linear_extrude(height=size.z, convexity=2, center=true) {
square([size.x, size.y], center=true); square([size.x, size.y], center=true);
} }
@ -90,8 +90,8 @@ module cube(size, center=undef, align=V_ALLPOS)
// d1 = The bottom diameter of the cylinder. (Before orientation.) // d1 = The bottom diameter of the cylinder. (Before orientation.)
// d2 = The top diameter of the cylinder. (Before orientation.) // d2 = The top diameter of the cylinder. (Before orientation.)
// orient = Orientation of the cylinder. Use the `ORIENT_` constants from `constants.scad`. Default: vertical. // orient = Orientation of the cylinder. Use the `ORIENT_` constants from `constants.scad`. Default: vertical.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_CENTER` // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `UP`
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=V_UP+V_BACK+V_RIGHT`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP+BACK+RIGHT`.
// Example: By Radius // Example: By Radius
// xdistribute(30) { // xdistribute(30) {
// cylinder(h=40, r=10); // cylinder(h=40, r=10);
@ -102,14 +102,14 @@ module cube(size, center=undef, align=V_ALLPOS)
// cylinder(h=40, d=25); // cylinder(h=40, d=25);
// cylinder(h=40, d1=25, d2=10); // cylinder(h=40, d1=25, d2=10);
// } // }
module cylinder(r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, l=undef, center=undef, orient=ORIENT_Z, align=ALIGN_POS) module cylinder(r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, l=undef, center=undef, orient=ORIENT_Z, align=UP)
{ {
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1); r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1);
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1); r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1);
l = first_defined([h, l]); l = first_defined([h, l]);
sides = segs(max(r1,r2)); sides = segs(max(r1,r2));
size = [r1*2, r1*2, l]; size = [r1*2, r1*2, l];
orient_and_align(size, orient, align, center, size2=[r2*2,r2*2], noncentered=ALIGN_POS, chain=true) { orient_and_align(size, orient, align, center, size2=[r2*2,r2*2], noncentered=UP, chain=true) {
linear_extrude(height=l, scale=r2/r1, convexity=2, center=true) { linear_extrude(height=l, scale=r2/r1, convexity=2, center=true) {
circle(r=r1, $fn=sides); circle(r=r1, $fn=sides);
} }
@ -129,10 +129,10 @@ module cylinder(r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=unde
// r = Radius of the sphere. // r = Radius of the sphere.
// d = Diameter of the sphere. // d = Diameter of the sphere.
// orient = Orientation of the sphere, if you don't like where the vertices lay. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the sphere, if you don't like where the vertices lay. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the sphere. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the sphere. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// staggered_sphere(d=100); // staggered_sphere(d=100);
module sphere(r=undef, d=undef, orient=ORIENT_Z, align=V_CENTER) module sphere(r=undef, d=undef, orient=ORIENT_Z, align=CENTER)
{ {
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
sides = segs(r); sides = segs(r);

View file

@ -57,10 +57,10 @@ include <constants.scad>
// fillet = Radius of fillet for edge rounding. Default: No filleting. // fillet = Radius of fillet for edge rounding. Default: No filleting.
// edges = Edges to chamfer/fillet. Use `EDGE` constants from constants.scad. Default: `EDGES_ALL` // edges = Edges to chamfer/fillet. Use `EDGE` constants from constants.scad. Default: `EDGES_ALL`
// trimcorners = If true, rounds or chamfers corners where three chamferred/filleted edges meet. Default: `true` // trimcorners = If true, rounds or chamfers corners where three chamferred/filleted edges meet. Default: `true`
// p1 = Align the cuboid's corner at `p1`, if given. Forces `align=V_UP+V_BACK+V_RIGHT`. // p1 = Align the cuboid's corner at `p1`, if given. Forces `align=UP+BACK+RIGHT`.
// p2 = If given with `p1`, defines the cornerpoints of the cuboid. // p2 = If given with `p1`, defines the cornerpoints of the cuboid.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_CENTER` // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `CENTER`
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=V_UP+V_BACK+V_RIGHT`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP+BACK+RIGHT`.
// //
// Example: Simple regular cube. // Example: Simple regular cube.
// cuboid(40); // cuboid(40);
@ -96,18 +96,18 @@ module cuboid(
if (is_def(p1)) { if (is_def(p1)) {
if (is_def(p2)) { if (is_def(p2)) {
translate([for (v=array_zip([p1,p2],0)) min(v)]) { translate([for (v=array_zip([p1,p2],0)) min(v)]) {
cuboid(size=vabs(p2-p1), chamfer=chamfer, fillet=fillet, edges=edges, trimcorners=trimcorners, align=V_ALLPOS) children(); cuboid(size=vabs(p2-p1), chamfer=chamfer, fillet=fillet, edges=edges, trimcorners=trimcorners, align=ALLPOS) children();
} }
} else { } else {
translate(p1) { translate(p1) {
cuboid(size=size, chamfer=chamfer, fillet=fillet, edges=edges, trimcorners=trimcorners, align=V_ALLPOS) children(); cuboid(size=size, chamfer=chamfer, fillet=fillet, edges=edges, trimcorners=trimcorners, align=ALLPOS) children();
} }
} }
} else { } else {
if (chamfer != undef) assertion(chamfer <= min(size)/2, "chamfer must be smaller than half the cube width, length, or height."); if (chamfer != undef) assertion(chamfer <= min(size)/2, "chamfer must be smaller than half the cube width, length, or height.");
if (fillet != undef) assertion(fillet <= min(size)/2, "fillet must be smaller than half the cube width, length, or height."); if (fillet != undef) assertion(fillet <= min(size)/2, "fillet must be smaller than half the cube width, length, or height.");
majrots = [[0,90,0], [90,0,0], [0,0,0]]; majrots = [[0,90,0], [90,0,0], [0,0,0]];
orient_and_align(size, ORIENT_Z, align, center=center, noncentered=V_ALLPOS, chain=true) { orient_and_align(size, ORIENT_Z, align, center=center, noncentered=ALLPOS, chain=true) {
if (chamfer != undef) { if (chamfer != undef) {
isize = [for (v = size) max(0.001, v-2*chamfer)]; isize = [for (v = size) max(0.001, v-2*chamfer)];
if (edges == EDGES_ALL && trimcorners) { if (edges == EDGES_ALL && trimcorners) {
@ -136,7 +136,7 @@ module cuboid(
for (za=[-1,1], ya=[-1,1], xa=[-1,1]) { for (za=[-1,1], ya=[-1,1], xa=[-1,1]) {
if (corner_edge_count(edges, [xa,ya,za]) > 2) { if (corner_edge_count(edges, [xa,ya,za]) > 2) {
translate(vmul([xa,ya,za]/2, size-[1,1,1]*chamfer*4/3)) { translate(vmul([xa,ya,za]/2, size-[1,1,1]*chamfer*4/3)) {
rot(from=V_UP, to=[xa,ya,za]) { rot(from=UP, to=[xa,ya,za]) {
upcube(chamfer*3); upcube(chamfer*3);
} }
} }
@ -320,8 +320,8 @@ module upcube(size=[1,1,1]) {siz = scalar_vec3(size); up(siz[2]/2) cube(size=siz
// h = Height of the prism. // h = Height of the prism.
// shift = [x, y] amount to shift the center of the top with respect to the center of the bottom. // shift = [x, y] amount to shift the center of the top with respect to the center of the bottom.
// orient = Orientation of the prismoid. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the prismoid. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the prismoid by the axis-negative (size1) end. Use the `V_` constants from `constants.scad`. Default: `ALIGN_POS`. // align = Alignment of the prismoid by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `UP`.
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=ALIGN_POS`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP`.
// //
// Example: Rectangular Pyramid // Example: Rectangular Pyramid
// prismoid(size1=[40,40], size2=[0,0], h=20); // prismoid(size1=[40,40], size2=[0,0], h=20);
@ -341,13 +341,13 @@ module upcube(size=[1,1,1]) {siz = scalar_vec3(size); up(siz[2]/2) cube(size=siz
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5]); // prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5]);
module prismoid( module prismoid(
size1=[1,1], size2=[1,1], h=1, shift=[0,0], size1=[1,1], size2=[1,1], h=1, shift=[0,0],
orient=ORIENT_Z, align=ALIGN_POS, center=undef orient=ORIENT_Z, align=UP, center=undef
) { ) {
eps = 0.001; eps = 0.001;
shiftby = point3d(point2d(shift)); shiftby = point3d(point2d(shift));
s1 = [max(size1.x, eps), max(size1.y, eps)]; s1 = [max(size1.x, eps), max(size1.y, eps)];
s2 = [max(size2.x, eps), max(size2.y, eps)]; s2 = [max(size2.x, eps), max(size2.y, eps)];
orient_and_align([s1.x,s1.y,h], orient, align, center, size2=s2, shift=shift, noncentered=ALIGN_POS, chain=true) { orient_and_align([s1.x,s1.y,h], orient, align, center, size2=s2, shift=shift, noncentered=UP, chain=true) {
polyhedron( polyhedron(
points=[ points=[
[+s2.x/2, +s2.y/2, +h/2] + shiftby, [+s2.x/2, +s2.y/2, +h/2] + shiftby,
@ -394,7 +394,7 @@ module prismoid(
// r2 = radius of vertical edge fillets at top. // r2 = radius of vertical edge fillets at top.
// shift = [x, y] amount to shift the center of the top with respect to the center of the bottom. // shift = [x, y] amount to shift the center of the top with respect to the center of the bottom.
// orient = Orientation of the prismoid. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the prismoid. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the prismoid by the axis-negative (`size1`) end. Use the `V_` constants from `constants.scad`. Default: `V_UP`. // align = Alignment of the prismoid by the axis-negative (`size1`) end. Use the constants from `constants.scad`. Default: `UP`.
// center = vertically center the prism. Overrides `align`. // center = vertically center the prism. Overrides `align`.
// //
// Example: Rounded Pyramid // Example: Rounded Pyramid
@ -408,7 +408,7 @@ module prismoid(
module rounded_prismoid( module rounded_prismoid(
size1, size2, h, shift=[0,0], size1, size2, h, shift=[0,0],
r=undef, r1=undef, r2=undef, r=undef, r1=undef, r2=undef,
align=V_UP, orient=ORIENT_Z, center=undef align=UP, orient=ORIENT_Z, center=undef
) { ) {
eps = 0.001; eps = 0.001;
maxrad1 = min(size1.x/2, size1.y/2); maxrad1 = min(size1.x/2, size1.y/2);
@ -416,7 +416,7 @@ module rounded_prismoid(
rr1 = min(maxrad1, (r1!=undef)? r1 : r); rr1 = min(maxrad1, (r1!=undef)? r1 : r);
rr2 = min(maxrad2, (r2!=undef)? r2 : r); rr2 = min(maxrad2, (r2!=undef)? r2 : r);
shiftby = point3d(shift); shiftby = point3d(shift);
orient_and_align([size1.x, size1.y, h], orient, align, center, size2=size2, shift=shift, noncentered=ALIGN_POS, chain=true) { orient_and_align([size1.x, size1.y, h], orient, align, center, size2=size2, shift=shift, noncentered=UP, chain=true) {
down(h/2) { down(h/2) {
hull() { hull() {
linear_extrude(height=eps, center=false, convexity=2) { linear_extrude(height=eps, center=false, convexity=2) {
@ -452,14 +452,14 @@ module rounded_prismoid(
// Arguments: // Arguments:
// size = [width, thickness, height] // size = [width, thickness, height]
// orient = The axis to place the hypotenuse along. Only accepts `ORIENT_X`, `ORIENT_Y`, or `ORIENT_Z` from `constants.scad`. Default: `ORIENT_Y`. // orient = The axis to place the hypotenuse along. Only accepts `ORIENT_X`, `ORIENT_Y`, or `ORIENT_Z` from `constants.scad`. Default: `ORIENT_Y`.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_UP+V_BACK+V_RIGHT`. // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `UP+BACK+RIGHT`.
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=V_UP+V_BACK+V_RIGHT`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP+BACK+RIGHT`.
// //
// Example: Centered // Example: Centered
// right_triangle([60, 10, 40], center=true); // right_triangle([60, 10, 40], center=true);
// Example: *Non*-Centered // Example: *Non*-Centered
// right_triangle([60, 10, 40]); // right_triangle([60, 10, 40]);
module right_triangle(size=[1, 1, 1], orient=ORIENT_Y, align=V_ALLPOS, center=undef) module right_triangle(size=[1, 1, 1], orient=ORIENT_Y, align=ALLPOS, center=undef)
{ {
size = scalar_vec3(size); size = scalar_vec3(size);
orient_and_align(size, align=align, center=center, chain=true) { orient_and_align(size, align=align, center=center, chain=true) {
@ -547,8 +547,8 @@ module right_triangle(size=[1, 1, 1], orient=ORIENT_Y, align=V_ALLPOS, center=un
// fillet2 = The radius of the fillet on the axis-positive end of the cylinder. // fillet2 = The radius of the fillet on the axis-positive end of the cylinder.
// realign = If true, rotate the cylinder by half the angle of one face. // realign = If true, rotate the cylinder by half the angle of one face.
// orient = Orientation of the cylinder. Use the `ORIENT_` constants from `constants.scad`. Default: vertical. // orient = Orientation of the cylinder. Use the `ORIENT_` constants from `constants.scad`. Default: vertical.
// align = Alignment of the cylinder. Use the `V_` constants from `constants.scad`. Default: centered. // align = Alignment of the cylinder. Use the constants from `constants.scad`. Default: centered.
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=ALIGN_POS`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP`.
// //
// Example: By Radius // Example: By Radius
// xdistribute(30) { // xdistribute(30) {
@ -591,7 +591,7 @@ module cyl(
chamfang=undef, chamfang1=undef, chamfang2=undef, chamfang=undef, chamfang1=undef, chamfang2=undef,
fillet=undef, fillet1=undef, fillet2=undef, fillet=undef, fillet1=undef, fillet2=undef,
circum=false, realign=false, from_end=false, circum=false, realign=false, from_end=false,
orient=ORIENT_Z, align=V_CENTER, center=undef orient=ORIENT_Z, align=CENTER, center=undef
) { ) {
r1 = get_radius(r1, r, d1, d, 1); r1 = get_radius(r1, r, d1, d, 1);
r2 = get_radius(r2, r, d2, d, 1); r2 = get_radius(r2, r, d2, d, 1);
@ -753,7 +753,7 @@ module cyl(
module downcyl(r=undef, h=undef, l=undef, d=undef, d1=undef, d2=undef, r1=undef, r2=undef) module downcyl(r=undef, h=undef, l=undef, d=undef, d1=undef, d2=undef, r1=undef, r2=undef)
{ {
l = first_defined([l, h, 1]); l = first_defined([l, h, 1]);
cyl(r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, l=l, align=V_DOWN) children(); cyl(r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, l=l, align=DOWN) children();
} }
@ -775,8 +775,8 @@ module downcyl(r=undef, h=undef, l=undef, d=undef, d1=undef, d2=undef, r1=undef,
// d = Optional diameter of cylinder. (use instead of `r`) // d = Optional diameter of cylinder. (use instead of `r`)
// d1 = Optional diameter of left (X-) end of cylinder. // d1 = Optional diameter of left (X-) end of cylinder.
// d2 = Optional diameter of right (X+) end of cylinder. // d2 = Optional diameter of right (X+) end of cylinder.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_CENTER` // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `CENTER`
// center = If given, overrides `align`. A `true` value sets `align=V_CENTER`, `false` sets `align=ALIGN_POS`. // center = If given, overrides `align`. A `true` value sets `align=CENTER`, `false` sets `align=UP`.
// //
// Example: By Radius // Example: By Radius
// ydistribute(50) { // ydistribute(50) {
@ -789,7 +789,7 @@ module downcyl(r=undef, h=undef, l=undef, d=undef, d1=undef, d2=undef, r1=undef,
// xcyl(l=35, d=20); // xcyl(l=35, d=20);
// xcyl(l=35, d1=30, d2=10); // xcyl(l=35, d1=30, d2=10);
// } // }
module xcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, align=V_CENTER, center=undef) module xcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, align=CENTER, center=undef)
{ {
cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=ORIENT_X, align=align, center=center) children(); cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=ORIENT_X, align=align, center=center) children();
} }
@ -813,8 +813,8 @@ module xcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h
// d = Diameter of cylinder. // d = Diameter of cylinder.
// d1 = Diameter of front (Y-) end of one. // d1 = Diameter of front (Y-) end of one.
// d2 = Diameter of back (Y+) end of one. // d2 = Diameter of back (Y+) end of one.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_CENTER` // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `CENTER`
// center = Overrides `align` if given. If true, `align=V_CENTER`, if false, `align=ALIGN_POS`. // center = Overrides `align` if given. If true, `align=CENTER`, if false, `align=UP`.
// //
// Example: By Radius // Example: By Radius
// xdistribute(50) { // xdistribute(50) {
@ -827,7 +827,7 @@ module xcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h
// ycyl(l=35, d=20); // ycyl(l=35, d=20);
// ycyl(l=35, d1=30, d2=10); // ycyl(l=35, d1=30, d2=10);
// } // }
module ycyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, align=V_CENTER, center=undef) module ycyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, align=CENTER, center=undef)
{ {
cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=ORIENT_Y, align=align, center=center) children(); cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=ORIENT_Y, align=align, center=center) children();
} }
@ -851,8 +851,8 @@ module ycyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h
// d = Diameter of cylinder. // d = Diameter of cylinder.
// d1 = Diameter of front (Y-) end of one. // d1 = Diameter of front (Y-) end of one.
// d2 = Diameter of back (Y+) end of one. // d2 = Diameter of back (Y+) end of one.
// align = The side of the origin to align to. Use `V_` constants from `constants.scad`. Default: `V_CENTER` // align = The side of the origin to align to. Use constants from `constants.scad`. Default: `CENTER`
// center = Overrides `align` if given. If true, `align=V_CENTER`, if false, `align=ALIGN_POS`. // center = Overrides `align` if given. If true, `align=CENTER`, if false, `align=UP`.
// //
// Example: By Radius // Example: By Radius
// xdistribute(50) { // xdistribute(50) {
@ -865,7 +865,7 @@ module ycyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h
// zcyl(l=35, d=20); // zcyl(l=35, d=20);
// zcyl(l=35, d1=30, d2=10); // zcyl(l=35, d1=30, d2=10);
// } // }
module zcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, align=V_CENTER, center=undef) module zcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, align=CENTER, center=undef)
{ {
cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=ORIENT_Z, align=align, center=center) children(); cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=ORIENT_Z, align=align, center=center) children();
} }
@ -902,7 +902,7 @@ module zcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h
// id2 = Inner diameter of top of tube. // id2 = Inner diameter of top of tube.
// realign = If true, rotate the tube by half the angle of one face. // realign = If true, rotate the tube by half the angle of one face.
// orient = Orientation of the tube. Use the `ORIENT_` constants from `constants.scad`. Default: vertical. // orient = Orientation of the tube. Use the `ORIENT_` constants from `constants.scad`. Default: vertical.
// align = Alignment of the tube. Use the `V_` constants from `constants.scad`. Default: centered. // align = Alignment of the tube. Use the constants from `constants.scad`. Default: centered.
// //
// Example: These all Produce the Same Tube // Example: These all Produce the Same Tube
// tube(h=30, or=40, wall=5); // tube(h=30, or=40, wall=5);
@ -923,7 +923,7 @@ module tube(
od=undef, od1=undef, od2=undef, od=undef, od1=undef, od2=undef,
ir=undef, id=undef, ir1=undef, ir=undef, id=undef, ir1=undef,
ir2=undef, id1=undef, id2=undef, ir2=undef, id1=undef, id2=undef,
center=undef, orient=ORIENT_Z, align=ALIGN_POS, center=undef, orient=ORIENT_Z, align=UP,
realign=false realign=false
) { ) {
r1 = first_defined([or1, od1/2, r1, d1/2, or, od/2, r, d/2, ir1+wall, id1/2+wall, ir+wall, id/2+wall]); r1 = first_defined([or1, od1/2, r1, d1/2, or, od/2, r, d/2, ir1+wall, id1/2+wall, ir+wall, id/2+wall]);
@ -966,7 +966,7 @@ module tube(
// od = outer diameter of the torus. (use with 'ir' or 'id') // od = outer diameter of the torus. (use with 'ir' or 'id')
// id = inside diameter of the torus. (use with 'or' or 'od') // id = inside diameter of the torus. (use with 'or' or 'od')
// orient = Orientation of the torus. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the torus. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the torus. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the torus. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: // Example:
// // These all produce the same torus. // // These all produce the same torus.
@ -979,7 +979,7 @@ module torus(
r2=undef, d2=undef, r2=undef, d2=undef,
or=undef, od=undef, or=undef, od=undef,
ir=undef, id=undef, ir=undef, id=undef,
orient=ORIENT_Z, align=V_CENTER, center=undef orient=ORIENT_Z, align=CENTER, center=undef
) { ) {
orr = get_radius(r=or, d=od, dflt=1.0); orr = get_radius(r=or, d=od, dflt=1.0);
irr = get_radius(r=ir, d=id, dflt=0.5); irr = get_radius(r=ir, d=id, dflt=0.5);
@ -1009,10 +1009,10 @@ module torus(
// d = Diameter of the sphere. // d = Diameter of the sphere.
// circum = If true, circumscribes the perfect sphere of the given radius/diameter. // circum = If true, circumscribes the perfect sphere of the given radius/diameter.
// orient = Orientation of the sphere, if you don't like where the vertices lay. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the sphere, if you don't like where the vertices lay. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the sphere. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the sphere. Use the constants from `constants.scad`. Default: `CENTER`.
// Example: // Example:
// spheroid(d=100, circum=true, $fn=10); // spheroid(d=100, circum=true, $fn=10);
module spheroid(r=undef, d=undef, circum=false, orient=V_UP, align=V_CENTER) module spheroid(r=undef, d=undef, circum=false, orient=UP, align=CENTER)
{ {
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
hsides = segs(r); hsides = segs(r);
@ -1040,11 +1040,11 @@ module spheroid(r=undef, d=undef, circum=false, orient=V_UP, align=V_CENTER)
// d = Diameter of the sphere. // d = Diameter of the sphere.
// circum = If true, circumscribes the perfect sphere of the given size. // circum = If true, circumscribes the perfect sphere of the given size.
// orient = Orientation of the sphere, if you don't like where the vertices lay. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the sphere, if you don't like where the vertices lay. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the sphere. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the sphere. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: // Example:
// staggered_sphere(d=100, circum=true, $fn=10); // staggered_sphere(d=100, circum=true, $fn=10);
module staggered_sphere(r=undef, d=undef, circum=false, orient=V_UP, align=V_CENTER) { module staggered_sphere(r=undef, d=undef, circum=false, orient=UP, align=CENTER) {
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
sides = segs(r); sides = segs(r);
vsides = max(3, ceil(sides/2))+1; vsides = max(3, ceil(sides/2))+1;
@ -1146,7 +1146,7 @@ module teardrop2d(r=1, d=undef, ang=45, cap_h=undef)
// ang = Angle of hat walls from the Z axis. (Default: 45 degrees) // ang = Angle of hat walls from the Z axis. (Default: 45 degrees)
// cap_h = If given, height above center where the shape will be truncated. // cap_h = If given, height above center where the shape will be truncated.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// teardrop(r=30, h=10, ang=30); // teardrop(r=30, h=10, ang=30);
@ -1154,7 +1154,7 @@ module teardrop2d(r=1, d=undef, ang=45, cap_h=undef)
// teardrop(r=30, h=10, ang=30, cap_h=40); // teardrop(r=30, h=10, ang=30, cap_h=40);
// Example: Close Crop // Example: Close Crop
// teardrop(r=30, h=10, ang=30, cap_h=20); // teardrop(r=30, h=10, ang=30, cap_h=20);
module teardrop(r=undef, d=undef, l=undef, h=undef, ang=45, cap_h=undef, orient=ORIENT_Y, align=V_CENTER) module teardrop(r=undef, d=undef, l=undef, h=undef, ang=45, cap_h=undef, orient=ORIENT_Y, align=CENTER)
{ {
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
l = first_defined([l, h, 1]); l = first_defined([l, h, 1]);
@ -1182,7 +1182,7 @@ module teardrop(r=undef, d=undef, l=undef, h=undef, ang=45, cap_h=undef, orient=
// cap_h = height above sphere center to truncate teardrop shape. // cap_h = height above sphere center to truncate teardrop shape.
// maxang = angle of cone on top from vertical. // maxang = angle of cone on top from vertical.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// onion(r=30, maxang=30); // onion(r=30, maxang=30);
@ -1190,7 +1190,7 @@ module teardrop(r=undef, d=undef, l=undef, h=undef, ang=45, cap_h=undef, orient=
// onion(r=30, maxang=30, cap_h=40); // onion(r=30, maxang=30, cap_h=40);
// Example: Close Crop // Example: Close Crop
// onion(r=30, maxang=30, cap_h=20); // onion(r=30, maxang=30, cap_h=20);
module onion(cap_h=undef, r=undef, d=undef, maxang=45, h=undef, orient=ORIENT_Z, align=V_CENTER) module onion(cap_h=undef, r=undef, d=undef, maxang=45, h=undef, orient=ORIENT_Z, align=CENTER)
{ {
r = get_radius(r=r, d=d, dflt=1); r = get_radius(r=r, d=d, dflt=1);
h = first_defined([cap_h, h]); h = first_defined([cap_h, h]);
@ -1225,11 +1225,11 @@ module onion(cap_h=undef, r=undef, d=undef, maxang=45, h=undef, orient=ORIENT_Z,
// wall = height of rectangular portion of the strut. // wall = height of rectangular portion of the strut.
// ang = angle that the trianglar side will converge at. // ang = angle that the trianglar side will converge at.
// orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: // Example:
// narrowing_strut(w=10, l=100, wall=5, ang=30); // narrowing_strut(w=10, l=100, wall=5, ang=30);
module narrowing_strut(w=10, l=100, wall=5, ang=30, orient=ORIENT_Y, align=V_UP) module narrowing_strut(w=10, l=100, wall=5, ang=30, orient=ORIENT_Y, align=UP)
{ {
h = wall + w/2/tan(ang); h = wall + w/2/tan(ang);
size = [w, h, l]; size = [w, h, l];
@ -1269,13 +1269,13 @@ module narrowing_strut(w=10, l=100, wall=5, ang=30, orient=ORIENT_Y, align=V_UP)
// strut = the width of the diagonal brace. // strut = the width of the diagonal brace.
// wall = the thickness of the thinned portion of the wall. // wall = the thickness of the thinned portion of the wall.
// orient = Orientation of the length axis of the wall. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the length axis of the wall. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// thinning_wall(h=50, l=80, thick=4); // thinning_wall(h=50, l=80, thick=4);
// Example: Trapezoidal // Example: Trapezoidal
// thinning_wall(h=50, l=[80,50], thick=4); // thinning_wall(h=50, l=[80,50], thick=4);
module thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orient=ORIENT_Z, align=V_CENTER) module thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orient=ORIENT_Z, align=CENTER)
{ {
l1 = (l[0] == undef)? l : l[0]; l1 = (l[0] == undef)? l : l[0];
l2 = (l[1] == undef)? l : l[1]; l2 = (l[1] == undef)? l : l[1];
@ -1413,11 +1413,11 @@ module thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orient=ORIEN
// strut = the width of the diagonal brace. // strut = the width of the diagonal brace.
// wall = the thickness of the thinned portion of the wall. // wall = the thickness of the thinned portion of the wall.
// orient = Orientation of the length axis of the wall. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the length axis of the wall. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// braced_thinning_wall(h=50, l=100, thick=5); // braced_thinning_wall(h=50, l=100, thick=5);
module braced_thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orient=ORIENT_Y, align=V_CENTER) module braced_thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orient=ORIENT_Y, align=CENTER)
{ {
dang = atan((h-2*strut)/(l-2*strut)); dang = atan((h-2*strut)/(l-2*strut));
dlen = (h-2*strut)/sin(dang); dlen = (h-2*strut)/sin(dang);
@ -1465,8 +1465,8 @@ module braced_thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orien
// wall = the thickness of the thinned portion of the wall. // wall = the thickness of the thinned portion of the wall.
// diagonly = boolean, which denotes only the diagonal side (hypotenuse) should be thick. // diagonly = boolean, which denotes only the diagonal side (hypotenuse) should be thick.
// orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// center = If true, centers shape. If false, overrides `align` with `V_UP+V_BACK`. // center = If true, centers shape. If false, overrides `align` with `UP+BACK`.
// //
// Example: Centered // Example: Centered
// thinning_triangle(h=50, l=80, thick=4, ang=30, strut=5, wall=2, center=true); // thinning_triangle(h=50, l=80, thick=4, ang=30, strut=5, wall=2, center=true);
@ -1474,12 +1474,12 @@ module braced_thinning_wall(h=50, l=100, thick=5, ang=30, strut=5, wall=2, orien
// thinning_triangle(h=50, l=80, thick=4, ang=30, strut=5, wall=2, center=false); // thinning_triangle(h=50, l=80, thick=4, ang=30, strut=5, wall=2, center=false);
// Example: Diagonal Brace Only // Example: Diagonal Brace Only
// thinning_triangle(h=50, l=80, thick=4, ang=30, strut=5, wall=2, diagonly=true, center=false); // thinning_triangle(h=50, l=80, thick=4, ang=30, strut=5, wall=2, diagonly=true, center=false);
module thinning_triangle(h=50, l=100, thick=5, ang=30, strut=5, wall=3, diagonly=false, center=undef, orient=ORIENT_Y, align=V_CENTER) module thinning_triangle(h=50, l=100, thick=5, ang=30, strut=5, wall=3, diagonly=false, center=undef, orient=ORIENT_Y, align=CENTER)
{ {
dang = atan(h/l); dang = atan(h/l);
dlen = h/sin(dang); dlen = h/sin(dang);
size = [thick, l, h]; size = [thick, l, h];
orient_and_align(size, orient, align, center=center, noncentered=V_UP+V_BACK, orig_orient=ORIENT_Y, chain=true) { orient_and_align(size, orient, align, center=center, noncentered=UP+BACK, orig_orient=ORIENT_Y, chain=true) {
difference() { difference() {
union() { union() {
if (!diagonly) { if (!diagonly) {
@ -1524,7 +1524,7 @@ module thinning_triangle(h=50, l=100, thick=5, ang=30, strut=5, wall=3, diagonly
// max_bridge = maximum bridging distance between cross-braces. // max_bridge = maximum bridging distance between cross-braces.
// strut = the width of the cross-braces. // strut = the width of the cross-braces.
// orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// sparse_strut(h=40, l=100, thick=3); // sparse_strut(h=40, l=100, thick=3);
@ -1534,7 +1534,7 @@ module thinning_triangle(h=50, l=100, thick=5, ang=30, strut=5, wall=3, diagonly
// sparse_strut(h=40, l=100, thick=3, strut=2, maxang=45); // sparse_strut(h=40, l=100, thick=3, strut=2, maxang=45);
// Example: Longer max_bridge // Example: Longer max_bridge
// sparse_strut(h=40, l=100, thick=3, strut=2, maxang=45, max_bridge=30); // sparse_strut(h=40, l=100, thick=3, strut=2, maxang=45, max_bridge=30);
module sparse_strut(h=50, l=100, thick=4, maxang=30, strut=5, max_bridge=20, orient=ORIENT_Y, align=V_CENTER) module sparse_strut(h=50, l=100, thick=4, maxang=30, strut=5, max_bridge=20, orient=ORIENT_Y, align=CENTER)
{ {
zoff = h/2 - strut/2; zoff = h/2 - strut/2;
yoff = l/2 - strut/2; yoff = l/2 - strut/2;
@ -1591,7 +1591,7 @@ module sparse_strut(h=50, l=100, thick=4, maxang=30, strut=5, max_bridge=20, ori
// max_bridge = maximum bridging distance between cross-braces. // max_bridge = maximum bridging distance between cross-braces.
// strut = the width of the cross-braces. // strut = the width of the cross-braces.
// orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// sparse_strut3d(h=30, w=30, l=100); // sparse_strut3d(h=30, w=30, l=100);
@ -1601,7 +1601,7 @@ module sparse_strut(h=50, l=100, thick=4, maxang=30, strut=5, max_bridge=20, ori
// sparse_strut3d(h=30, w=30, l=100, strut=2, maxang=50); // sparse_strut3d(h=30, w=30, l=100, strut=2, maxang=50);
// Example: Smaller max_bridge // Example: Smaller max_bridge
// sparse_strut3d(h=30, w=30, l=100, strut=2, maxang=50, max_bridge=20); // sparse_strut3d(h=30, w=30, l=100, strut=2, maxang=50, max_bridge=20);
module sparse_strut3d(h=50, l=100, w=50, thick=3, maxang=40, strut=3, max_bridge=30, orient=ORIENT_Y, align=V_CENTER) module sparse_strut3d(h=50, l=100, w=50, thick=3, maxang=40, strut=3, max_bridge=30, orient=ORIENT_Y, align=CENTER)
{ {
xoff = w - thick; xoff = w - thick;
@ -1687,7 +1687,7 @@ module sparse_strut3d(h=50, l=100, w=50, thick=3, maxang=40, strut=3, max_bridge
// strut = the width of the cross-braces. // strut = the width of the cross-braces.
// wall = thickness of corrugations. // wall = thickness of corrugations.
// orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the length axis of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the shape. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the shape. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: Typical Shape // Example: Typical Shape
// corrugated_wall(h=50, l=100); // corrugated_wall(h=50, l=100);
@ -1695,7 +1695,7 @@ module sparse_strut3d(h=50, l=100, w=50, thick=3, maxang=40, strut=3, max_bridge
// corrugated_wall(h=50, l=100, strut=8); // corrugated_wall(h=50, l=100, strut=8);
// Example: Thicker Wall // Example: Thicker Wall
// corrugated_wall(h=50, l=100, strut=8, wall=3); // corrugated_wall(h=50, l=100, strut=8, wall=3);
module corrugated_wall(h=50, l=100, thick=5, strut=5, wall=2, orient=ORIENT_Y, align=V_CENTER) module corrugated_wall(h=50, l=100, thick=5, strut=5, wall=2, orient=ORIENT_Y, align=CENTER)
{ {
amplitude = (thick - wall) / 2; amplitude = (thick - wall) / 2;
period = min(15, thick * 2); period = min(15, thick * 2);
@ -1760,8 +1760,8 @@ module noop() children();
// d1 = bottom diameter of pie slice. // d1 = bottom diameter of pie slice.
// d2 = top diameter of pie slice. // d2 = top diameter of pie slice.
// orient = Orientation of the pie slice. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the pie slice. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the pie slice. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the pie slice. Use the constants from `constants.scad`. Default: `CENTER`.
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=ALIGN_POS`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP`.
// //
// Example: Cylindrical Pie Slice // Example: Cylindrical Pie Slice
// pie_slice(ang=45, l=20, r=30); // pie_slice(ang=45, l=20, r=30);
@ -1771,7 +1771,7 @@ module pie_slice(
ang=30, l=undef, ang=30, l=undef,
r=10, r1=undef, r2=undef, r=10, r1=undef, r2=undef,
d=undef, d1=undef, d2=undef, d=undef, d1=undef, d2=undef,
orient=ORIENT_Z, align=ALIGN_POS, orient=ORIENT_Z, align=UP,
center=undef, h=undef center=undef, h=undef
) { ) {
l = first_defined([l, h, 1]); l = first_defined([l, h, 1]);
@ -1808,7 +1808,7 @@ module pie_slice(
// ang = angle between faces to fillet. // ang = angle between faces to fillet.
// overlap = overlap size for unioning with faces. // overlap = overlap size for unioning with faces.
// orient = Orientation of the fillet. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`. // orient = Orientation of the fillet. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_X`.
// align = Alignment of the fillet. Use the `V_` or `ALIGN_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the fillet. Use the constants from `constants.scad`. Default: `CENTER`.
// //
// Example: // Example:
// union() { // union() {
@ -1819,7 +1819,7 @@ module pie_slice(
// //
// Example: // Example:
// interior_fillet(l=40, r=10, orient=ORIENT_Y_90); // interior_fillet(l=40, r=10, orient=ORIENT_Y_90);
module interior_fillet(l=1.0, r=1.0, ang=90, overlap=0.01, orient=ORIENT_X, align=V_CENTER) { module interior_fillet(l=1.0, r=1.0, ang=90, overlap=0.01, orient=ORIENT_X, align=CENTER) {
dy = r/tan(ang/2); dy = r/tan(ang/2);
size = [l,r,r]; size = [l,r,r];
orient_and_align(size, orient, align, orig_orient=ORIENT_X, chain=true) { orient_and_align(size, orient, align, orig_orient=ORIENT_X, chain=true) {
@ -1903,7 +1903,7 @@ module slot(
// sa = starting angle. (Default: 0.0) // sa = starting angle. (Default: 0.0)
// ea = ending angle. (Default: 90.0) // ea = ending angle. (Default: 90.0)
// orient = Orientation of the arced slot. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the arced slot. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the arced slot. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the arced slot. Use the constants from `constants.scad`. Default: `CENTER`.
// center = If true, centers vertically. If false, drops flush with XY plane. Overrides `align`. // center = If true, centers vertically. If false, drops flush with XY plane. Overrides `align`.
// $fn2 = The $fn value to use on the small round endcaps. The major arcs are still based on $fn. Default: $fn // $fn2 = The $fn value to use on the small round endcaps. The major arcs are still based on $fn. Default: $fn
// //
@ -1916,7 +1916,7 @@ module arced_slot(
sr=undef, sr1=undef, sr2=undef, sr=undef, sr1=undef, sr2=undef,
sd=undef, sd1=undef, sd2=undef, sd=undef, sd1=undef, sd2=undef,
sa=0, ea=90, cp=[0,0,0], sa=0, ea=90, cp=[0,0,0],
orient=ORIENT_Z, align=V_CENTER, orient=ORIENT_Z, align=CENTER,
$fn2 = undef $fn2 = undef
) { ) {
r = get_radius(r=r, d=d, dflt=2); r = get_radius(r=r, d=d, dflt=2);
@ -1929,7 +1929,7 @@ module arced_slot(
translate(cp) { translate(cp) {
zrot(sa) { zrot(sa) {
difference() { difference() {
pie_slice(ang=da, l=h, r1=r+sr1, r2=r+sr2, orient=ORIENT_Z, align=V_CENTER); pie_slice(ang=da, l=h, r1=r+sr1, r2=r+sr2, orient=ORIENT_Z, align=CENTER);
cylinder(h=h+0.1, r1=r-sr1, r2=r-sr2, center=true); cylinder(h=h+0.1, r1=r-sr1, r2=r-sr2, center=true);
} }
right(r) cylinder(h=h, r1=sr1, r2=sr2, center=true, $fn=fn_minor); right(r) cylinder(h=h, r1=sr1, r2=sr2, center=true, $fn=fn_minor);

View file

@ -59,10 +59,10 @@ include <constants.scad>
// ang = Overhang angle for slider, to facilitate supportless printig. // ang = Overhang angle for slider, to facilitate supportless printig.
// slop = Printer-specific slop value to make parts fit exactly. // slop = Printer-specific slop value to make parts fit exactly.
// orient = Orientation of the slider. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the slider. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the slider. Use the `V_` constants from `constants.scad`. Default: `V_UP`. // align = Alignment of the slider. Use the constants from `constants.scad`. Default: `UP`.
// Example: // Example:
// slider(l=30, base=10, wall=4, slop=0.2, orient=ORIENT_Y); // slider(l=30, base=10, wall=4, slop=0.2, orient=ORIENT_Y);
module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, slop=PRINTER_SLOP, orient=ORIENT_Y, align=V_UP) module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, slop=PRINTER_SLOP, orient=ORIENT_Y, align=UP)
{ {
full_width = w + 2*wall; full_width = w + 2*wall;
full_height = h + base; full_height = h + base;
@ -70,18 +70,18 @@ module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, slop=PRINTER_SLOP, orie
orient_and_align([full_width, l, h+2*base], orient, align, orig_orient=ORIENT_Y) { orient_and_align([full_width, l, h+2*base], orient, align, orig_orient=ORIENT_Y) {
down(base+h/2) { down(base+h/2) {
// Base // Base
cuboid([full_width, l, base-slop], chamfer=2, edges=EDGE_TOP_FR+EDGE_TOP_BK+EDGES_Z_ALL, align=V_UP); cuboid([full_width, l, base-slop], chamfer=2, edges=EDGE_TOP_FR+EDGE_TOP_BK+EDGES_Z_ALL, align=UP);
// Wall // Wall
xflip_copy(offset=w/2+slop) { xflip_copy(offset=w/2+slop) {
cuboid([wall, l, full_height], chamfer=2, edges=EDGE_TOP_RT+EDGE_FR_RT+EDGE_BK_RT, align=V_UP+V_RIGHT); cuboid([wall, l, full_height], chamfer=2, edges=EDGE_TOP_RT+EDGE_FR_RT+EDGE_BK_RT, align=UP+RIGHT);
} }
// Sliders // Sliders
up(base+h/2) { up(base+h/2) {
xflip_copy(offset=w/2+slop+0.02) { xflip_copy(offset=w/2+slop+0.02) {
bev_h = h/2*tan(ang); bev_h = h/2*tan(ang);
prismoid([l, h], [l-w, 0], h=bev_h+0.01, orient=ORIENT_XNEG, align=V_LEFT); prismoid([l, h], [l-w, 0], h=bev_h+0.01, orient=ORIENT_XNEG, align=LEFT);
} }
} }
} }
@ -102,10 +102,10 @@ module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, slop=PRINTER_SLOP, orie
// chamfer = Size of chamfer at end of rail. // chamfer = Size of chamfer at end of rail.
// ang = Overhang angle for slider, to facilitate supportless printig. // ang = Overhang angle for slider, to facilitate supportless printig.
// orient = Orientation of the rail. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`. // orient = Orientation of the rail. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// align = Alignment of the rail. Use the `V_` constants from `constants.scad`. Default: `V_UP`. // align = Alignment of the rail. Use the constants from `constants.scad`. Default: `UP`.
// Example: // Example:
// rail(l=100, w=10, h=10); // rail(l=100, w=10, h=10);
module rail(l=30, w=10, h=10, chamfer=1.0, ang=30, orient=ORIENT_Y, align=V_UP) module rail(l=30, w=10, h=10, chamfer=1.0, ang=30, orient=ORIENT_Y, align=UP)
{ {
attack_ang = 30; attack_ang = 30;
attack_len = 2; attack_len = 2;

View file

@ -66,8 +66,8 @@ function _trpzd_thread_pt(thread, threads, start, starts, astep, asteps, part, p
// bevel = if true, bevel the thread ends. Default: true // bevel = if true, bevel the thread ends. Default: true
// starts = The number of lead starts. Default = 1 // starts = The number of lead starts. Default = 1
// orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the rod. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the rod. Use the constants from `constants.scad`. Default: `CENTER`.
// center = If given, overrides `align`. A true value sets `align=V_CENTER`, false sets `align=ALIGN_POS`. // center = If given, overrides `align`. A true value sets `align=CENTER`, false sets `align=UP`.
// Examples: // Examples:
// trapezoidal_threaded_rod(d=10, l=100, pitch=2, thread_angle=15, $fn=32); // trapezoidal_threaded_rod(d=10, l=100, pitch=2, thread_angle=15, $fn=32);
// trapezoidal_threaded_rod(d=3/8*25.4, l=20, pitch=1/8*25.4, thread_angle=29, $fn=32); // trapezoidal_threaded_rod(d=3/8*25.4, l=20, pitch=1/8*25.4, thread_angle=29, $fn=32);
@ -77,7 +77,7 @@ function _trpzd_thread_pt(thread, threads, start, starts, astep, asteps, part, p
// trapezoidal_threaded_rod(d=10, l=40, pitch=3, thread_angle=15, left_handed=true, starts=3, $fn=36); // trapezoidal_threaded_rod(d=10, l=40, pitch=3, thread_angle=15, left_handed=true, starts=3, $fn=36);
// trapezoidal_threaded_rod(d=25, l=100, pitch=10, thread_depth=8/3, thread_angle=50, starts=4, center=false, $fa=2, $fs=2); // trapezoidal_threaded_rod(d=25, l=100, pitch=10, thread_depth=8/3, thread_angle=50, starts=4, center=false, $fa=2, $fs=2);
// trapezoidal_threaded_rod(d=50, l=75, pitch=8, thread_angle=30, starts=3, bevel=true); // trapezoidal_threaded_rod(d=50, l=75, pitch=8, thread_angle=30, starts=3, bevel=true);
// trapezoidal_threaded_rod(l=25, d=10, pitch=2, thread_angle=15, starts=3, $fa=1, $fs=1, orient=ORIENT_X, align=ALIGN_POS); // trapezoidal_threaded_rod(l=25, d=10, pitch=2, thread_angle=15, starts=3, $fa=1, $fs=1, orient=ORIENT_X, align=UP);
module trapezoidal_threaded_rod( module trapezoidal_threaded_rod(
d=10, d=10,
l=100, l=100,
@ -88,7 +88,7 @@ module trapezoidal_threaded_rod(
bevel=false, bevel=false,
starts=1, starts=1,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER, align=CENTER,
center=undef center=undef
) { ) {
astep = 360 / quantup(segs(d/2), starts); astep = 360 / quantup(segs(d/2), starts);
@ -253,9 +253,9 @@ module trapezoidal_threaded_rod(
// slop = printer slop calibration to allow for tight fitting of parts. default=0.2 // slop = printer slop calibration to allow for tight fitting of parts. default=0.2
// bevel = if true, bevel the thread ends. Default: true // bevel = if true, bevel the thread ends. Default: true
// orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the nut. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the nut. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// trapezoidal_threaded_nut(od=16, id=8, h=8, pitch=2, slop=0.2, align=V_UP); // trapezoidal_threaded_nut(od=16, id=8, h=8, pitch=2, slop=0.2, align=UP);
// trapezoidal_threaded_nut(od=17.4, id=10, h=10, pitch=2, slop=0.2, left_handed=true); // trapezoidal_threaded_nut(od=17.4, id=10, h=10, pitch=2, slop=0.2, left_handed=true);
// trapezoidal_threaded_nut(od=17.4, id=10, h=10, pitch=2, thread_angle=15, starts=3, $fa=1, $fs=1); // trapezoidal_threaded_nut(od=17.4, id=10, h=10, pitch=2, thread_angle=15, starts=3, $fa=1, $fs=1);
module trapezoidal_threaded_nut( module trapezoidal_threaded_nut(
@ -270,7 +270,7 @@ module trapezoidal_threaded_nut(
bevel=true, bevel=true,
slop=PRINTER_SLOP, slop=PRINTER_SLOP,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
depth = min((thread_depth==undef? pitch/2 : thread_depth), pitch/2/tan(thread_angle)); depth = min((thread_depth==undef? pitch/2 : thread_depth), pitch/2/tan(thread_angle));
orient_and_align([od/cos(30),od,h], orient, align) { orient_and_align([od/cos(30),od,h], orient, align) {
@ -312,10 +312,10 @@ module trapezoidal_threaded_nut(
// left_handed = if true, create left-handed threads. Default = false // left_handed = if true, create left-handed threads. Default = false
// bevel = if true, bevel the thread ends. Default: false // bevel = if true, bevel the thread ends. Default: false
// orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the rod. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the rod. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// threaded_rod(d=10, l=30, pitch=1.25, left_handed=true, $fa=1, $fs=1); // threaded_rod(d=10, l=30, pitch=1.25, left_handed=true, $fa=1, $fs=1);
module threaded_rod(d=10, l=100, pitch=2, left_handed=false, bevel=false, orient=ORIENT_Z, align=V_CENTER) { module threaded_rod(d=10, l=100, pitch=2, left_handed=false, bevel=false, orient=ORIENT_Z, align=CENTER) {
trapezoidal_threaded_rod( trapezoidal_threaded_rod(
d=d, l=l, pitch=pitch, d=d, l=l, pitch=pitch,
thread_depth=pitch*3*sqrt(3)/8, thread_depth=pitch*3*sqrt(3)/8,
@ -342,14 +342,14 @@ module threaded_rod(d=10, l=100, pitch=2, left_handed=false, bevel=false, orient
// bevel = if true, bevel the thread ends. Default: false // bevel = if true, bevel the thread ends. Default: false
// slop = printer slop calibration to allow for tight fitting of parts. default=0.2 // slop = printer slop calibration to allow for tight fitting of parts. default=0.2
// orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the nut. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the nut. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// threaded_nut(od=16, id=8, h=8, pitch=1.25, left_handed=true, slop=0.2, $fa=1, $fs=1); // threaded_nut(od=16, id=8, h=8, pitch=1.25, left_handed=true, slop=0.2, $fa=1, $fs=1);
module threaded_nut( module threaded_nut(
od=16, id=10, h=10, od=16, id=10, h=10,
pitch=2, left_handed=false, pitch=2, left_handed=false,
bevel=false, slop=0.2, bevel=false, slop=0.2,
orient=ORIENT_Z, align=V_CENTER orient=ORIENT_Z, align=CENTER
) { ) {
trapezoidal_threaded_nut( trapezoidal_threaded_nut(
od=od, id=id, h=h, od=od, id=id, h=h,
@ -376,7 +376,7 @@ module threaded_nut(
// bevel = if true, bevel the thread ends. Default: false // bevel = if true, bevel the thread ends. Default: false
// starts = The number of lead starts. Default = 1 // starts = The number of lead starts. Default = 1
// orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the rod. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the rod. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// metric_trapezoidal_threaded_rod(d=10, l=30, pitch=2, left_handed=true, $fa=1, $fs=1); // metric_trapezoidal_threaded_rod(d=10, l=30, pitch=2, left_handed=true, $fa=1, $fs=1);
module metric_trapezoidal_threaded_rod( module metric_trapezoidal_threaded_rod(
@ -385,7 +385,7 @@ module metric_trapezoidal_threaded_rod(
starts=1, starts=1,
bevel=false, bevel=false,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
trapezoidal_threaded_rod( trapezoidal_threaded_rod(
d=d, l=l, d=d, l=l,
@ -415,7 +415,7 @@ module metric_trapezoidal_threaded_rod(
// starts = The number of lead starts. Default = 1 // starts = The number of lead starts. Default = 1
// slop = printer slop calibration to allow for tight fitting of parts. default=0.2 // slop = printer slop calibration to allow for tight fitting of parts. default=0.2
// orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the nut. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the nut. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// metric_trapezoidal_threaded_nut(od=16, id=10, h=10, pitch=2, left_handed=true, bevel=true, $fa=1, $fs=1); // metric_trapezoidal_threaded_nut(od=16, id=10, h=10, pitch=2, left_handed=true, bevel=true, $fa=1, $fs=1);
module metric_trapezoidal_threaded_nut( module metric_trapezoidal_threaded_nut(
@ -426,7 +426,7 @@ module metric_trapezoidal_threaded_nut(
bevel=false, bevel=false,
slop=PRINTER_SLOP, slop=PRINTER_SLOP,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
trapezoidal_threaded_nut( trapezoidal_threaded_nut(
od=od, id=id, h=h, od=od, id=id, h=h,
@ -457,7 +457,7 @@ module metric_trapezoidal_threaded_nut(
// left_handed = if true, create left-handed threads. Default = false // left_handed = if true, create left-handed threads. Default = false
// bevel = if true, bevel the thread ends. Default: false // bevel = if true, bevel the thread ends. Default: false
// orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the rod. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the rod. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// acme_threaded_rod(d=3/8*25.4, l=20, pitch=1/8*25.4, $fn=32); // acme_threaded_rod(d=3/8*25.4, l=20, pitch=1/8*25.4, $fn=32);
// acme_threaded_rod(d=10, l=40, pitch=2, starts=3, $fa=1, $fs=1); // acme_threaded_rod(d=10, l=40, pitch=2, starts=3, $fa=1, $fs=1);
@ -469,7 +469,7 @@ module acme_threaded_rod(
left_handed=false, left_handed=false,
bevel=false, bevel=false,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
trapezoidal_threaded_rod( trapezoidal_threaded_rod(
d=d, l=l, pitch=pitch, d=d, l=l, pitch=pitch,
@ -500,7 +500,7 @@ module acme_threaded_rod(
// bevel = if true, bevel the thread ends. Default: false // bevel = if true, bevel the thread ends. Default: false
// slop = printer slop calibration to allow for tight fitting of parts. default=0.2 // slop = printer slop calibration to allow for tight fitting of parts. default=0.2
// orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the nut. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the nut. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// acme_threaded_nut(od=16, id=3/8*25.4, h=8, pitch=1/8*25.4, slop=0.2); // acme_threaded_nut(od=16, id=3/8*25.4, h=8, pitch=1/8*25.4, slop=0.2);
// acme_threaded_nut(od=16, id=10, h=10, pitch=2, starts=3, slop=0.2, $fa=1, $fs=1); // acme_threaded_nut(od=16, id=10, h=10, pitch=2, starts=3, slop=0.2, $fa=1, $fs=1);
@ -513,7 +513,7 @@ module acme_threaded_nut(
bevel=false, bevel=false,
slop=PRINTER_SLOP, slop=PRINTER_SLOP,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
trapezoidal_threaded_nut( trapezoidal_threaded_nut(
od=od, id=id, h=h, pitch=pitch, od=od, id=id, h=h, pitch=pitch,
@ -543,7 +543,7 @@ module acme_threaded_nut(
// bevel = if true, bevel the thread ends. Default: false // bevel = if true, bevel the thread ends. Default: false
// starts = The number of lead starts. Default = 1 // starts = The number of lead starts. Default = 1
// orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the rod. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the rod. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the rod. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// square_threaded_rod(d=10, l=30, pitch=2, starts=2, $fn=32); // square_threaded_rod(d=10, l=30, pitch=2, starts=2, $fn=32);
module square_threaded_rod( module square_threaded_rod(
@ -552,7 +552,7 @@ module square_threaded_rod(
bevel=false, bevel=false,
starts=1, starts=1,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
trapezoidal_threaded_rod( trapezoidal_threaded_rod(
d=d, l=l, pitch=pitch, d=d, l=l, pitch=pitch,
@ -581,7 +581,7 @@ module square_threaded_rod(
// starts = The number of lead starts. Default = 1 // starts = The number of lead starts. Default = 1
// slop = printer slop calibration to allow for tight fitting of parts. default=0.2 // slop = printer slop calibration to allow for tight fitting of parts. default=0.2
// orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`. // orient = Orientation of the nut. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Z`.
// align = Alignment of the nut. Use the `V_` constants from `constants.scad`. Default: `V_CENTER`. // align = Alignment of the nut. Use the constants from `constants.scad`. Default: `CENTER`.
// Examples: // Examples:
// square_threaded_nut(od=16, id=10, h=10, pitch=2, starts=2, slop=0.15, $fn=32); // square_threaded_nut(od=16, id=10, h=10, pitch=2, starts=2, slop=0.15, $fn=32);
module square_threaded_nut( module square_threaded_nut(
@ -592,7 +592,7 @@ module square_threaded_nut(
starts=1, starts=1,
slop=PRINTER_SLOP, slop=PRINTER_SLOP,
orient=ORIENT_Z, orient=ORIENT_Z,
align=V_CENTER align=CENTER
) { ) {
trapezoidal_threaded_nut( trapezoidal_threaded_nut(
od=od, id=id, h=h, pitch=pitch, od=od, id=id, h=h, pitch=pitch,

View file

@ -215,7 +215,7 @@ module torx_drive2d(size) {
// center = If true, centers bit vertically. // center = If true, centers bit vertically.
// Examples: // Examples:
// torx_drive(size=30, l=10, $fa=1, $fs=1); // torx_drive(size=30, l=10, $fa=1, $fs=1);
module torx_drive(size, l=5, center=undef, orient=ORIENT_Z, align=V_UP) { module torx_drive(size, l=5, center=undef, orient=ORIENT_Z, align=UP) {
od = torx_outer_diam(size); od = torx_outer_diam(size);
orient_and_align([od, od, l], orient, align, center) { orient_and_align([od, od, l], orient, align, center) {
linear_extrude(height=l, convexity=4, center=true) { linear_extrude(height=l, convexity=4, center=true) {

View file

@ -254,7 +254,7 @@ module up(z=0) translate([0,0,z]) children();
// //
// Arguments: // Arguments:
// a = Scalar angle or vector of XYZ rotation angles to rotate by, in degrees. // a = Scalar angle or vector of XYZ rotation angles to rotate by, in degrees.
// v = vector for the axis of rotation. Default: [0,0,1] or V_UP // v = vector for the axis of rotation. Default: [0,0,1] or UP
// cp = centerpoint to rotate around. Default: [0,0,0] // cp = centerpoint to rotate around. Default: [0,0,0]
// from = Starting vector for vector-based rotations. // from = Starting vector for vector-based rotations.
// to = Target vector for vector-based rotations. // to = Target vector for vector-based rotations.
@ -270,7 +270,7 @@ module up(z=0) translate([0,0,z]) children();
// //
// Example: // Example:
// #cube([2,4,9]); // #cube([2,4,9]);
// rot(from=V_UP, to=V_LEFT+V_BACK) cube([2,4,9]); // rot(from=UP, to=LEFT+BACK) cube([2,4,9]);
module rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false) module rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false)
{ {
if (is_def(cp)) { if (is_def(cp)) {
@ -700,7 +700,7 @@ module spread(p1=undef, p2=undef, spacing=undef, l=undef, n=undef)
// } // }
module xspread(spacing=undef, n=undef, l=undef, sp=undef) module xspread(spacing=undef, n=undef, l=undef, sp=undef)
{ {
spread(l=l*V_RIGHT, spacing=spacing*V_RIGHT, n=n, p1=sp) children(); spread(l=l*RIGHT, spacing=spacing*RIGHT, n=n, p1=sp) children();
} }
@ -735,7 +735,7 @@ module xspread(spacing=undef, n=undef, l=undef, sp=undef)
// } // }
module yspread(spacing=undef, n=undef, l=undef, sp=undef) module yspread(spacing=undef, n=undef, l=undef, sp=undef)
{ {
spread(l=l*V_BACK, spacing=spacing*V_BACK, n=n, p1=sp) children(); spread(l=l*BACK, spacing=spacing*BACK, n=n, p1=sp) children();
} }
@ -770,7 +770,7 @@ module yspread(spacing=undef, n=undef, l=undef, sp=undef)
// } // }
module zspread(spacing=undef, n=undef, l=undef, sp=undef) module zspread(spacing=undef, n=undef, l=undef, sp=undef)
{ {
spread(l=l*V_UP, spacing=spacing*V_UP, n=n, p1=sp) children(); spread(l=l*UP, spacing=spacing*UP, n=n, p1=sp) children();
} }
@ -798,12 +798,12 @@ module zspread(spacing=undef, n=undef, l=undef, sp=undef)
// `$idx` is set to the index number of each child being copied. // `$idx` is set to the index number of each child being copied.
// //
// Example: // Example:
// distribute(sizes=[100, 30, 50], dir=V_UP) { // distribute(sizes=[100, 30, 50], dir=UP) {
// sphere(r=50); // sphere(r=50);
// cube([10,20,30], center=true); // cube([10,20,30], center=true);
// cylinder(d=30, h=50, center=true); // cylinder(d=30, h=50, center=true);
// } // }
module distribute(spacing=undef, sizes=undef, dir=V_RIGHT, l=undef) module distribute(spacing=undef, sizes=undef, dir=RIGHT, l=undef)
{ {
gaps = ($children < 2)? [0] : gaps = ($children < 2)? [0] :
is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] : is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] :
@ -849,7 +849,7 @@ module distribute(spacing=undef, sizes=undef, dir=V_RIGHT, l=undef)
// } // }
module xdistribute(spacing=10, sizes=undef, l=undef) module xdistribute(spacing=10, sizes=undef, l=undef)
{ {
dir = V_RIGHT; dir = RIGHT;
gaps = ($children < 2)? [0] : gaps = ($children < 2)? [0] :
is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] : is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] :
[for (i=[0:$children-2]) 0]; [for (i=[0:$children-2]) 0];
@ -894,7 +894,7 @@ module xdistribute(spacing=10, sizes=undef, l=undef)
// } // }
module ydistribute(spacing=10, sizes=undef, l=undef) module ydistribute(spacing=10, sizes=undef, l=undef)
{ {
dir = V_BACK; dir = BACK;
gaps = ($children < 2)? [0] : gaps = ($children < 2)? [0] :
is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] : is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] :
[for (i=[0:$children-2]) 0]; [for (i=[0:$children-2]) 0];
@ -939,7 +939,7 @@ module ydistribute(spacing=10, sizes=undef, l=undef)
// } // }
module zdistribute(spacing=10, sizes=undef, l=undef) module zdistribute(spacing=10, sizes=undef, l=undef)
{ {
dir = V_UP; dir = UP;
gaps = ($children < 2)? [0] : gaps = ($children < 2)? [0] :
is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] : is_def(sizes)? [for (i=[0:$children-2]) sizes[i]/2 + sizes[i+1]/2] :
[for (i=[0:$children-2]) 0]; [for (i=[0:$children-2]) 0];
@ -1003,12 +1003,12 @@ module zdistribute(spacing=10, sizes=undef, l=undef)
// grid2d(spacing=10, stagger=true, in_poly=hexregion) { // grid2d(spacing=10, stagger=true, in_poly=hexregion) {
// // Note: You must use for(var=[val]) or let(var=val) // // Note: You must use for(var=[val]) or let(var=val)
// // to set vars from $pos or other special vars in this scope. // // to set vars from $pos or other special vars in this scope.
// let (ref_v = (normalize([0,0,50]-point3d($pos)) + V_UP)/2) // let (ref_v = (normalize([0,0,50]-point3d($pos)) + UP)/2)
// half_of(v=-ref_v, cp=[0,0,5]) // half_of(v=-ref_v, cp=[0,0,5])
// zrot(180/6) // zrot(180/6)
// cylinder(h=20, d=10/cos(180/6)+0.01, $fn=6); // cylinder(h=20, d=10/cos(180/6)+0.01, $fn=6);
// } // }
module grid2d(size=undef, spacing=undef, cols=undef, rows=undef, stagger=false, scale=[1,1,1], in_poly=undef, orient=ORIENT_Z, align=V_CENTER) module grid2d(size=undef, spacing=undef, cols=undef, rows=undef, stagger=false, scale=[1,1,1], in_poly=undef, orient=ORIENT_Z, align=CENTER)
{ {
assert_in_list("stagger", stagger, [false, true, "alt"]); assert_in_list("stagger", stagger, [false, true, "alt"]);
scl = vmul(scalar_vec3(scale, 1), (stagger!=false? [0.5, sin(60), 0] : [1,1,0])); scl = vmul(scalar_vec3(scale, 1), (stagger!=false? [0.5, sin(60), 0] : [1,1,0]));
@ -1161,27 +1161,27 @@ module grid3d(xa=[0], ya=[0], za=[0], n=undef, spacing=undef)
// rot_copies([[45,0,0],[0,45,90],[90,-45,270]]) 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);
// //
// Example: // Example:
// rot_copies([45, 90, 135], v=V_DOWN+V_BACK) // rot_copies([45, 90, 135], v=DOWN+BACK)
// yrot(90) cylinder(h=20, r1=5, r2=0); // yrot(90) cylinder(h=20, r1=5, r2=0);
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0); // color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
// //
// Example: // Example:
// rot_copies(n=6, v=V_DOWN+V_BACK) // rot_copies(n=6, v=DOWN+BACK)
// yrot(90) cylinder(h=20, r1=5, r2=0); // yrot(90) cylinder(h=20, r1=5, r2=0);
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0); // color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
// //
// Example: // Example:
// rot_copies(n=6, v=V_DOWN+V_BACK, delta=[10,0,0]) // rot_copies(n=6, v=DOWN+BACK, delta=[10,0,0])
// yrot(90) cylinder(h=20, r1=5, r2=0); // yrot(90) cylinder(h=20, r1=5, r2=0);
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0); // color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
// //
// Example: // Example:
// rot_copies(n=6, v=V_UP+V_FWD, delta=[10,0,0], sa=45) // rot_copies(n=6, v=UP+FWD, delta=[10,0,0], sa=45)
// yrot(90) cylinder(h=20, r1=5, r2=0); // yrot(90) cylinder(h=20, r1=5, r2=0);
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0); // color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
// //
// Example: // Example:
// rot_copies(n=6, v=V_DOWN+V_BACK, delta=[20,0,0], subrot=false) // rot_copies(n=6, v=DOWN+BACK, delta=[20,0,0], subrot=false)
// yrot(90) cylinder(h=20, r1=5, r2=0); // yrot(90) cylinder(h=20, r1=5, r2=0);
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0); // color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
module rot_copies(rots=[], v=undef, cp=[0,0,0], count=undef, n=undef, sa=0, offset=0, delta=[0,0,0], subrot=true) module rot_copies(rots=[], v=undef, cp=[0,0,0], count=undef, n=undef, sa=0, offset=0, delta=[0,0,0], subrot=true)
@ -1254,7 +1254,7 @@ module xrot_copies(rots=[], cp=[0,0,0], n=undef, count=undef, sa=0, offset=0, r=
{ {
cnt = first_defined([count, n]); cnt = first_defined([count, n]);
sang = sa + offset; sang = sa + offset;
rot_copies(rots=rots, v=V_RIGHT, cp=cp, n=cnt, sa=sang, delta=[0, r, 0], subrot=subrot) children(); rot_copies(rots=rots, v=RIGHT, cp=cp, n=cnt, sa=sang, delta=[0, r, 0], subrot=subrot) children();
} }
@ -1307,7 +1307,7 @@ module yrot_copies(rots=[], cp=[0,0,0], n=undef, count=undef, sa=0, offset=0, r=
{ {
cnt = first_defined([count, n]); cnt = first_defined([count, n]);
sang = sa + offset; sang = sa + offset;
rot_copies(rots=rots, v=V_BACK, cp=cp, n=cnt, sa=sang, delta=[-r, 0, 0], subrot=subrot) children(); rot_copies(rots=rots, v=BACK, cp=cp, n=cnt, sa=sang, delta=[-r, 0, 0], subrot=subrot) children();
} }
@ -1360,7 +1360,7 @@ module zrot_copies(rots=[], cp=[0,0,0], n=undef, count=undef, sa=0, offset=0, r=
{ {
cnt = first_defined([count, n]); cnt = first_defined([count, n]);
sang = sa + offset; sang = sa + offset;
rot_copies(rots=rots, v=V_UP, cp=cp, n=cnt, sa=sang, delta=[r, 0, 0], subrot=subrot) children(); rot_copies(rots=rots, v=UP, cp=cp, n=cnt, sa=sang, delta=[r, 0, 0], subrot=subrot) children();
} }
@ -1572,7 +1572,7 @@ module ovoid_spread(r=undef, d=undef, n=100, cone_ang=90, scale=[1,1,1], perp=tr
$rad = r; $rad = r;
translate($pos) { translate($pos) {
if (perp) { if (perp) {
rot(from=V_UP, to=xyz) children(); rot(from=UP, to=xyz) children();
} else { } else {
children(); children();
} }
@ -1613,8 +1613,8 @@ module ovoid_spread(r=undef, d=undef, n=100, cone_ang=90, scale=[1,1,1], perp=tr
// color("blue",0.25) zrot(45) cube([0.01,15,15], center=true); // color("blue",0.25) zrot(45) cube([0.01,15,15], center=true);
// //
// Example: // Example:
// 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); // mirror_copy(UP+BACK, cp=[0,-5,-5]) rot(from=UP, to=BACK+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); // color("blue",0.25) translate([0,-5,-5]) rot(from=UP, to=BACK+UP) cube([15,15,0.01], center=true);
module mirror_copy(v=[0,0,1], offset=0, cp=[0,0,0]) module mirror_copy(v=[0,0,1], offset=0, cp=[0,0,0])
{ {
nv = v/norm(v); nv = v/norm(v);
@ -1750,23 +1750,23 @@ module zflip_copy(offset=0, cp=[0,0,0])
// Slices an object at a cut plane, and masks away everything that is on one side. // Slices an object at a cut plane, and masks away everything that is on one side.
// //
// Arguments: // Arguments:
// v = Normal of plane to slice at. Keeps everything on the side the normal points to. Default: [0,0,1] (V_UP) // v = Normal of plane to slice at. Keeps everything on the side the normal points to. Default: [0,0,1] (UP)
// cp = If 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] // cp = If 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]
// s = Mask 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 // s = Mask 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
// planar = If 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. // planar = If true, this becomes a 2D operation. When planar, a `v` of `UP` or `DOWN` becomes equivalent of `BACK` and `FWD` respectively.
// //
// Examples: // Examples:
// half_of(V_DOWN+V_BACK, cp=[0,-10,0]) cylinder(h=40, r1=10, r2=0, center=false); // half_of(DOWN+BACK, cp=[0,-10,0]) cylinder(h=40, r1=10, r2=0, center=false);
// half_of(V_DOWN+V_LEFT, s=200) sphere(d=150); // half_of(DOWN+LEFT, s=200) sphere(d=150);
// Example(2D): // Example(2D):
// half_of([1,1], planar=true) circle(d=50); // half_of([1,1], planar=true) circle(d=50);
module half_of(v=V_UP, cp=[0,0,0], s=100, planar=false) module half_of(v=UP, cp=[0,0,0], s=100, planar=false)
{ {
cp = is_scalar(cp)? cp*normalize(v) : cp; cp = is_scalar(cp)? cp*normalize(v) : cp;
if (cp != [0,0,0]) { if (cp != [0,0,0]) {
translate(cp) half_of(v=v, s=s, planar=planar) translate(-cp) children(); translate(cp) half_of(v=v, s=s, planar=planar) translate(-cp) children();
} else if (planar) { } else if (planar) {
v = (v==V_UP)? V_BACK : (v==V_DOWN)? V_FWD : v; v = (v==UP)? BACK : (v==DOWN)? FWD : v;
ang = atan2(v.y, v.x); ang = atan2(v.y, v.x);
difference() { difference() {
children(); children();
@ -1777,7 +1777,7 @@ module half_of(v=V_UP, cp=[0,0,0], s=100, planar=false)
} else { } else {
difference() { difference() {
children(); children();
rot(from=V_UP, to=-v) { rot(from=UP, to=-v) {
up(s/2) cube(s, center=true); up(s/2) cube(s, center=true);
} }
} }
@ -1806,7 +1806,7 @@ module half_of(v=V_UP, cp=[0,0,0], s=100, planar=false)
// top_half(planar=true) circle(r=20); // top_half(planar=true) circle(r=20);
module top_half(s=100, cp=[0,0,0], planar=false) module top_half(s=100, cp=[0,0,0], planar=false)
{ {
dir = planar? V_BACK : V_UP; dir = planar? BACK : UP;
cp = is_scalar(cp)? cp*dir : cp; cp = is_scalar(cp)? cp*dir : cp;
translate(cp) difference() { translate(cp) difference() {
translate(-cp) children(); translate(-cp) children();
@ -1843,7 +1843,7 @@ module top_half(s=100, cp=[0,0,0], planar=false)
// bottom_half(planar=true) circle(r=20); // bottom_half(planar=true) circle(r=20);
module bottom_half(s=100, cp=[0,0,0], planar=false) module bottom_half(s=100, cp=[0,0,0], planar=false)
{ {
dir = planar? V_FWD : V_DOWN; dir = planar? FWD : DOWN;
cp = is_scalar(cp)? cp*dir : cp; cp = is_scalar(cp)? cp*dir : cp;
translate(cp) difference() { translate(cp) difference() {
translate(-cp) children(); translate(-cp) children();
@ -1880,7 +1880,7 @@ module bottom_half(s=100, cp=[0,0,0], planar=false)
// left_half(planar=true) circle(r=20); // left_half(planar=true) circle(r=20);
module left_half(s=100, cp=[0,0,0], planar=false) module left_half(s=100, cp=[0,0,0], planar=false)
{ {
dir = V_LEFT; dir = LEFT;
cp = is_scalar(cp)? cp*dir : cp; cp = is_scalar(cp)? cp*dir : cp;
translate(cp) difference() { translate(cp) difference() {
translate(-cp) children(); translate(-cp) children();
@ -1917,7 +1917,7 @@ module left_half(s=100, cp=[0,0,0], planar=false)
// right_half(planar=true) circle(r=20); // right_half(planar=true) circle(r=20);
module right_half(s=100, cp=[0,0,0], planar=false) module right_half(s=100, cp=[0,0,0], planar=false)
{ {
dir = V_RIGHT; dir = RIGHT;
cp = is_scalar(cp)? cp*dir : cp; cp = is_scalar(cp)? cp*dir : cp;
translate(cp) difference() { translate(cp) difference() {
translate(-cp) children(); translate(-cp) children();
@ -1954,7 +1954,7 @@ module right_half(s=100, cp=[0,0,0], planar=false)
// front_half(planar=true) circle(r=20); // front_half(planar=true) circle(r=20);
module front_half(s=100, cp=[0,0,0], planar=false) module front_half(s=100, cp=[0,0,0], planar=false)
{ {
dir = V_FWD; dir = FWD;
cp = is_scalar(cp)? cp*dir : cp; cp = is_scalar(cp)? cp*dir : cp;
translate(cp) difference() { translate(cp) difference() {
translate(-cp) children(); translate(-cp) children();
@ -1991,7 +1991,7 @@ module front_half(s=100, cp=[0,0,0], planar=false)
// back_half(planar=true) circle(r=20); // back_half(planar=true) circle(r=20);
module back_half(s=100, cp=[0,0,0], planar=false) module back_half(s=100, cp=[0,0,0], planar=false)
{ {
dir = V_BACK; dir = BACK;
cp = is_scalar(cp)? cp*dir : cp; cp = is_scalar(cp)? cp*dir : cp;
translate(cp) difference() { translate(cp) difference() {
translate(-cp) children(); translate(-cp) children();
@ -2058,7 +2058,7 @@ module chain_hull()
// r = Radius of arc. // r = Radius of arc.
// d = Diameter of arc. // d = Diameter of arc.
// orient = The axis to align to. Use `ORIENT_` constants from `constants.scad` // orient = The axis to align to. Use `ORIENT_` constants from `constants.scad`
// align = The side of the origin the part should be aligned with. Use `V_` constants from `constants.scad` // align = The side of the origin the part should be aligned with. Use `` constants from `constants.scad`
// masksize = size of mask used to clear unused part of circle arc. should be larger than height or width of 2D shapes to extrude. // masksize = size of mask used to clear unused part of circle arc. should be larger than height or width of 2D shapes to extrude.
// caps = If true, spin the 2D shapes to make rounded caps the ends of the arc. // caps = If true, spin the 2D shapes to make rounded caps the ends of the arc.
// convexity = Max number of times a ray passes through the 2D shape's walls. // convexity = Max number of times a ray passes through the 2D shape's walls.
@ -2069,7 +2069,7 @@ module chain_hull()
// extrude_arc(arc=270, sa=45, r=40, caps=true, convexity=4, $fa=2, $fs=2) { // extrude_arc(arc=270, sa=45, r=40, caps=true, convexity=4, $fa=2, $fs=2) {
// polygon(points=pts); // polygon(points=pts);
// } // }
module extrude_arc(arc=90, sa=0, r=undef, d=undef, orient=ORIENT_Z, align=V_CENTER, masksize=100, caps=false, convexity=4) module extrude_arc(arc=90, sa=0, r=undef, d=undef, orient=ORIENT_Z, align=CENTER, masksize=100, caps=false, convexity=4)
{ {
eps = 0.001; eps = 0.001;
r = get_radius(r=r, d=d, dflt=100); r = get_radius(r=r, d=d, dflt=100);
@ -2192,7 +2192,7 @@ module shell2d(thickness, or=0, ir=0, fill=0, round=0)
// orientations and alignments without extra translate()s and rotate()s. // orientations and alignments without extra translate()s and rotate()s.
// Children should be vertically (Z-axis) oriented, and centered. // Children should be vertically (Z-axis) oriented, and centered.
// Non-extremity alignment points should be named via the `alignments` arg. // Non-extremity alignment points should be named via the `alignments` arg.
// Named alignments, as well as `ALIGN_NEG`/`ALIGN_POS` are aligned pre-rotation. // Named alignments are aligned pre-rotation.
// //
// Usage: // Usage:
// orient_and_align(size, [orient], [align], [center], [noncentered], [orig_orient], [orig_align], [alignments], [chain]) ... // orient_and_align(size, [orient], [align], [center], [noncentered], [orig_orient], [orig_align], [alignments], [chain]) ...
@ -2204,9 +2204,9 @@ module shell2d(thickness, or=0, ir=0, fill=0, round=0)
// orient = The axis to align to. Use `ORIENT_` constants from `constants.scad`. // orient = The axis to align to. Use `ORIENT_` constants from `constants.scad`.
// align = The side of the origin the part should be aligned with. // align = The side of the origin the part should be aligned with.
// center = If given, overrides `align`. If true, centers vertically. If false, `align` will be set to the value in `noncentered`. // center = If given, overrides `align`. If true, centers vertically. If false, `align` will be set to the value in `noncentered`.
// noncentered = The value to set `align` to if `center` == `false`. Default: `V_UP`. // noncentered = The value to set `align` to if `center` == `false`. Default: `UP`.
// orig_orient = The original orientation of the part. Default: `ORIENT_Z`. // orig_orient = The original orientation of the part. Default: `ORIENT_Z`.
// orig_align = The original alignment of the part. Default: `V_CENTER`. // orig_align = The original alignment of the part. Default: `CENTER`.
// alignments = A list of extra, non-standard connectors that can be aligned to. // alignments = A list of extra, non-standard connectors that can be aligned to.
// chain = If true, allow attachable children. // chain = If true, allow attachable children.
// //
@ -2220,19 +2220,19 @@ module shell2d(thickness, or=0, ir=0, fill=0, round=0)
// //
// Example: // Example:
// #cylinder(d=5, h=10); // #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([5,5,10], orient=ORIENT_Y, align=BACK, orig_align=UP) cylinder(d=5, h=10);
module orient_and_align( module orient_and_align(
size=undef, orient=ORIENT_Z, align=V_CENTER, size=undef, orient=ORIENT_Z, align=CENTER,
center=undef, noncentered=ALIGN_POS, center=undef, noncentered=TOP,
orig_orient=ORIENT_Z, orig_align=V_CENTER, orig_orient=ORIENT_Z, orig_align=CENTER,
size2=undef, shift=[0,0], size2=undef, shift=[0,0],
alignments=[], chain=false alignments=[], chain=false
) { ) {
size2 = point2d(default(size2, size)); size2 = point2d(default(size2, size));
shift = point2d(shift); shift = point2d(shift);
align = is_def(center)? (center? V_CENTER : noncentered) : align; align = is_def(center)? (center? CENTER : noncentered) : align;
m = matrix4_mult(concat( m = matrix4_mult(concat(
(orig_align==V_CENTER)? [] : [ (orig_align==CENTER)? [] : [
// If original alignment is not centered, center it. // If original alignment is not centered, center it.
matrix4_translate(vmul(size/2, -orig_align)) matrix4_translate(vmul(size/2, -orig_align))
], ],
@ -2245,9 +2245,9 @@ module orient_and_align(
($attach_to!=undef)? ( ($attach_to!=undef)? (
let( let(
conn = find_connector($attach_to, size.z, size, size2=size2, shift=shift), conn = find_connector($attach_to, size.z, size, size2=size2, shift=shift),
ang = vector_angle(conn[2],V_DOWN), ang = vector_angle(conn[2], DOWN),
axis = vector_axis(conn[2],V_DOWN), axis = vector_axis(conn[2], DOWN),
ang2 = (conn[2]==V_UP || conn[2]==V_DOWN)? 0 : 180-conn[3], ang2 = (conn[2]==UP || conn[2]==DOWN)? 0 : 180-conn[3],
axis2 = rotate_points3d([axis],[0,0,ang2])[0] axis2 = rotate_points3d([axis],[0,0,ang2])[0]
) [ ) [
matrix4_translate(-conn[1]), matrix4_translate(-conn[1]),
@ -2255,7 +2255,7 @@ module orient_and_align(
matrix4_rot_by_axis(axis2, ang) matrix4_rot_by_axis(axis2, ang)
] ]
) : concat( ) : concat(
(!is_scalar(align) && !is_str(align))? [] : [ (align==CENTER)? [] : [
let(conn = find_connector(align, size.z, size, size2=size2, shift=shift, extra_conns=alignments)) let(conn = find_connector(align, size.z, size, size2=size2, shift=shift, extra_conns=alignments))
matrix4_translate(-conn[1]) matrix4_translate(-conn[1])
], ],
@ -2263,10 +2263,6 @@ module orient_and_align(
matrix4_xrot(orient.x), matrix4_xrot(orient.x),
matrix4_yrot(orient.y), matrix4_yrot(orient.y),
matrix4_zrot(orient.z) matrix4_zrot(orient.z)
],
(!is_array(align) || align==[0,0,0])? [] : [
let(conn = find_connector(align, size.z, size, size2=size2, shift=shift))
matrix4_translate(conn[1])
] ]
) )
)); ));
@ -2295,15 +2291,6 @@ module orient_and_align(
// Internal. Not exposed.
function _str_char_split(s,delim,n=0,acc=[],word="") =
(n>=len(s))? concat(acc, [word]) :
(s[n]==delim)?
_str_char_split(s,delim,n+1,concat(acc,[word]),"") :
_str_char_split(s,delim,n+1,acc,str(word,s[n]));
// Function: connector() // Function: connector()
// Usage: // Usage:
// connector(name, pos, dir, [rot]) // connector(name, pos, dir, [rot])
@ -2314,7 +2301,7 @@ function _str_char_split(s,delim,n=0,acc=[],word="") =
// pos = The [X,Y,Z] position of the connector. // pos = The [X,Y,Z] position of the connector.
// dir = A vector pointing in the direction parts should project from the connector position. // dir = A vector pointing in the direction parts should project from the connector position.
// rot = If needed, the angle to rotate the part around the direction vector. // rot = If needed, the angle to rotate the part around the direction vector.
function connector(name, pos=[0,0,0], dir=V_UP, rot=0) = [name, pos, dir, rot]; function connector(name, pos=[0,0,0], dir=UP, rot=0) = [name, pos, dir, rot];
@ -2332,49 +2319,25 @@ function connector(name, pos=[0,0,0], dir=V_UP, rot=0) = [name, pos, dir, rot];
// extra_conns = A list of extra named connectors. // extra_conns = A list of extra named connectors.
function find_connector(align, h, size, size2=undef, shift=[0,0], extra_conns=[]) = function find_connector(align, h, size, size2=undef, shift=[0,0], extra_conns=[]) =
let( let(
eps = 1e-9,
shift = point3d(shift), shift = point3d(shift),
size = point3d(point2d(size)), size = point3d(point2d(size)),
size2 = (size2!=undef)? point3d(point2d(size2)) : size, size2 = (size2!=undef)? point3d(point2d(size2)) : size,
found = !is_str(align)? [] : search([align], extra_conns, num_returns_per_match=1)[0] found = !is_str(align)? [] : search([align], extra_conns, num_returns_per_match=1)[0]
) (found!=[])? extra_conns[found] : let( ) (found!=[])? extra_conns[found] : let(
words = is_scalar(align)? (
align==ALIGN_NEG? ["top"] :
align==ALIGN_POS? ["bottom"] :
["center"]
) : is_array(align)? align : _str_char_split(align,"-"),
ovec = is_array(align)? align :
sum([
for (word = words)
word=="left"? V_LEFT :
word=="right"? V_RIGHT :
word=="front"? V_FWD :
word=="back"? V_BACK :
word=="top"? V_UP :
word=="bottom"? V_DOWN :
word=="center"? V_ZERO :
assertion(false,
str(
"Alignment label '", align, "' is not known.",
(!extra_conns? "" : str(
" Try one of ", [for (v=extra_conns) v[0]], " or the standard alignments."
))
)
)
]),
top = [-size2/2+shift, shift, size2/2+shift], top = [-size2/2+shift, shift, size2/2+shift],
bot = [-size/2, V_ZERO, size/2], bot = [-size/2, CENTER, size/2],
toppt = [top[ovec.x+1].x, top[ovec.y+1].y, h/2], toppt = [top[align.x+1].x, top[align.y+1].y, h/2],
botpt = [bot[ovec.x+1].x, bot[ovec.y+1].y, -h/2], botpt = [bot[align.x+1].x, bot[align.y+1].y, -h/2],
pos = lerp(botpt, toppt, (ovec.z+1)/2), pos = lerp(botpt, toppt, (align.z+1)/2),
oang = ( oang = (
ovec == V_UP? 0 : align == UP? 0 :
ovec == V_DOWN? 0 : align == DOWN? 0 :
(norm([ovec.x,ovec.y]) < eps)? 0 : atan2(ovec.y, ovec.x)+90 (norm([align.x,align.y]) < EPSILON)? 0 :
atan2(align.y, align.x)+90
), ),
vec = ( vec = (
abs(ovec.z) > eps? ovec : abs(align.z) > EPSILON? align :
rotate_points3d([ovec], from=V_UP, to=toppt-botpt)[0] rotate_points3d([align], from=UP, to=toppt-botpt)[0]
) )
) [align, pos, vec, oang]; ) [align, pos, vec, oang];
@ -2393,9 +2356,9 @@ function find_connector(align, h, size, size2=undef, shift=[0,0], extra_conns=[]
// norot = If true, don't rotate children when aligning to the attachment point. // norot = If true, don't rotate children when aligning to the attachment point.
// Example: // Example:
// spheroid(d=20) { // spheroid(d=20) {
// attach("top") down(1.5) cyl(l=11.5, d1=10, d2=5, align="bottom"); // attach(TOP) down(1.5) cyl(l=11.5, d1=10, d2=5, align=BOTTOM);
// attach("right", "bottom") down(1.5) cyl(l=11.5, d1=10, d2=5); // attach(RIGHT, BOTTOM) down(1.5) cyl(l=11.5, d1=10, d2=5);
// attach("front") down(1.5) cyl(l=11.5, d1=10, d2=5, align="bottom"); // attach(FRONT) down(1.5) cyl(l=11.5, d1=10, d2=5, align=BOTTOM);
// } // }
module attach(name, to=undef, overlap=undef, norot=false) module attach(name, to=undef, overlap=undef, norot=false)
{ {
@ -2407,10 +2370,10 @@ module attach(name, to=undef, overlap=undef, norot=false)
ang = conn[3]; ang = conn[3];
$attach_to = to; $attach_to = to;
$attach_conn = conn; $attach_conn = conn;
if (norot || (norm(vec-V_UP)<1e-9 && ang==0)) { if (norot || (norm(vec-UP)<1e-9 && ang==0)) {
translate(pos) translate([0,0,-overlap]) children(); translate(pos) translate([0,0,-overlap]) children();
} else { } else {
translate(pos) rot(ang,from=V_UP,to=vec) translate([0,0,-overlap]) children(); translate(pos) rot(ang,from=UP,to=vec) translate([0,0,-overlap]) children();
} }
} }