1//////////////////////////////////////////////////////////////////////
2// LibFile: constants.scad
3// Constants for directions (used with anchoring), and for specifying line termination for
4// use with geometry.scad.
5// Includes:
6// include <BOSL2/std.scad>
7// FileSummary: Constants provided by the library
8
9//////////////////////////////////////////////////////////////////////
10
11// a value that the user should never enter randomly;
12// result of `dd if=/dev/random bs=32 count=1 |base64` :
13_UNDEF="LRG+HX7dy89RyHvDlAKvb9Y04OTuaikpx205CTh8BSI";
14
15// Section: General Constants
16
17// Constant: $slop
18// Description:
19// A number of printers, particularly FDM/FFF printers, tend to be a bit sloppy in their printing.
20// This has made it so that some parts won't fit together without adding a bit of extra slop space.
21// That is what the `$slop` value is for. The value for this will vary from printer to printer.
22// By default, we use a value of 0.00 so that parts should fit exactly for resin and other precision
23// printers. This value is measured in millimeters. When making your own parts, you should add
24// `$slop` to both sides of a hole that another part is to fit snugly into. For a loose fit, add
25// `2*$slop` to each side. This should be done for both X and Y axes. The Z axis will require a
26// slop that depends on your layer height and bridging settings, and hole sizes. We leave that as
27// a more complicated exercise for the user.
28// .
29// Note that the slop value is accessed using the {{get_slop()}} function. This function provides
30// the default value of 0 if you have not set `$slop`. This approach makes it possible for you to
31// set `$slop` in your programs without experiencing peculiar OpenSCAD issues having to do with multiple
32// definitions of the variable. If you write code that uses `$slop` be sure to reference it using {{get_slop()}}.
33// DefineHeader(NumList): Calibration
34// Calibration: To calibrate the `$slop` value for your printer, follow this procedure:
35// Print the Slop Calibration part from the example below.
36// Take the long block and orient it so the numbers are upright, facing you.
37// Take the plug and orient it so that the arrow points down, facing you.
38// Starting with the hole with the largest number in front of it, insert the small end of the plug into the hole.
39// If you can insert and remove the small end of the plug from the hole without much force, then try again with the hole with the next smaller number.
40// Repeat step 5 until you have found the hole with the smallest number that the plug fits into without much force.
41// The correct hole should hold the plug when the long block is turned upside-down.
42// The number in front of that hole will indicate the `$slop` value that is ideal for your printer.
43// Remember to set that slop value in your scripts after you include the BOSL2 library: ie: `$slop = 0.15;`
44// Example(3D,Med): Slop Calibration Part.
45// min_slop = 0.00;
46// slop_step = 0.05;
47// holes = 8;
48// holesize = [15,15,15];
49// height = 20;
50// gap = 5;
51// l = holes * (holesize.x + gap) + gap;
52// w = holesize.y + 2*gap;
53// h = holesize.z + 5;
54// diff("holes")
55// cuboid([l, w, h], anchor=BOT) {
56// for (i=[0:holes-1]) {
57// right((i-holes/2+0.5)*(holesize.x+gap)) {
58// s = min_slop + slop_step * i;
59// tag("holes") {
60// cuboid([holesize.x + 2*s, holesize.y + 2*s, h+0.2]);
61// fwd(w/2-1) xrot(90) linear_extrude(1.1) {
62// text(
63// text=format_fixed(s,2),
64// size=0.4*holesize.x,
65// halign="center",
66// valign="center"
67// );
68// }
69// }
70// }
71// }
72// }
73// back(holesize.y*2.5) {
74// difference() {
75// union() {
76// cuboid([holesize.x+10, holesize.y+10, 15], anchor=BOT);
77// cuboid([holesize.x, holesize.y, 15+holesize.z], anchor=BOT);
78// }
79// up(3) fwd((holesize.y+10)/2) {
80// prismoid([holesize.x/2,1], [0,1], h=holesize.y-6);
81// }
82// }
83// }
84// Example(2D): Where to add `$slop` gaps.
85// $slop = 0.2;
86// difference() {
87// square([20,12],center=true);
88// back(3) square([10+2*$slop,11],center=true);
89// }
90// back(8) {
91// rect([15,5],anchor=FWD);
92// rect([10,8],anchor=BACK);
93// }
94// color("#000") {
95// arrow_path = [[5.1,6.1], [6.0,7.1], [8,7.1], [10.5,10]];
96// xflip_copy()
97// stroke(arrow_path, width=0.3, endcap1="arrow2");
98// xcopies(21) back(10.5) {
99// back(1.8) text("$slop", size=1.5, halign="center");
100// text("gap", size=1.5, halign="center");
101// }
102// }
103
104// Function: get_slop()
105// Usage:
106// slop = get_slop();
107// Description:
108// Returns the current $slop value, or the default value if the user did not set $slop.
109// Always acess the `$slop` variable using this function.
110function get_slop() = is_undef($slop) ? 0 : $slop;
111
112
113// Constant: INCH
114// Description:
115// The number of millimeters in an inch.
116// Example(2D):
117// square(2*INCH, center=true);
118// Example(3D):
119// cube([4,3,2.5]*INCH, center=true);
120INCH = 25.4;
121
122
123
124// Section: Directional Vectors
125// Vectors useful for `rotate()`, `mirror()`, and `anchor` arguments for `cuboid()`, `cyl()`, etc.
126
127// Constant: LEFT
128// Topics: Constants, Vectors
129// See Also: RIGHT, FRONT, BACK, UP, DOWN, CENTER
130// Description: Vector pointing left. [-1,0,0]
131// Example(3D): Usage with `anchor`
132// cuboid(20, anchor=LEFT);
133LEFT = [-1, 0, 0];
134
135// Constant: RIGHT
136// Topics: Constants, Vectors
137// See Also: LEFT, FRONT, BACK, UP, DOWN, CENTER
138// Description: Vector pointing right. [1,0,0]
139// Example(3D): Usage with `anchor`
140// cuboid(20, anchor=RIGHT);
141RIGHT = [ 1, 0, 0];
142
143// Constant: FRONT
144// Aliases: FWD, FORWARD
145// Topics: Constants, Vectors
146// See Also: LEFT, RIGHT, BACK, UP, DOWN, CENTER
147// Description: Vector pointing forward. [0,-1,0]
148// Example(3D): Usage with `anchor`
149// cuboid(20, anchor=FRONT);
150FRONT = [ 0, -1, 0];
151FWD = FRONT;
152FORWARD = FRONT;
153
154// Constant: BACK
155// Topics: Constants, Vectors
156// See Also: LEFT, RIGHT, FRONT, UP, DOWN, CENTER
157// Description: Vector pointing back. [0,1,0]
158// Example(3D): Usage with `anchor`
159// cuboid(20, anchor=BACK);
160BACK = [ 0, 1, 0];
161
162// Constant: BOTTOM
163// Aliases: BOT, DOWN
164// Topics: Constants, Vectors
165// See Also: LEFT, RIGHT, FRONT, BACK, UP, CENTER
166// Description: Vector pointing down. [0,0,-1]
167// Example(3D): Usage with `anchor`
168// cuboid(20, anchor=BOTTOM);
169BOTTOM = [ 0, 0, -1];
170BOT = BOTTOM;
171DOWN = BOTTOM;
172
173// Constant: TOP
174// Aliases: UP
175// Topics: Constants, Vectors
176// See Also: LEFT, RIGHT, FRONT, BACK, DOWN, CENTER
177// Description: Vector pointing up. [0,0,1]
178// Example(3D): Usage with `anchor`
179// cuboid(20, anchor=TOP);
180TOP = [ 0, 0, 1];
181UP = TOP;
182
183// Constant: CENTER
184// Aliases: CTR, CENTRE
185// Topics: Constants, Vectors
186// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN
187// Description: Zero vector. Centered. [0,0,0]
188// Example(3D): Usage with `anchor`
189// cuboid(20, anchor=CENTER);
190CENTER = [ 0, 0, 0]; // Centered zero vector.
191CTR = CENTER;
192CENTRE = CENTER;
193
194
195// Section: Line specifiers
196// Used by functions in geometry.scad for specifying whether two points
197// are treated as an unbounded line, a ray with one endpoint, or a segment
198// with two endpoints.
199
200// Constant: SEGMENT
201// Topics: Constants, Lines
202// See Also: RAY, LINE
203// Description: Treat a line as a segment. [true, true]
204// Example: Usage with line_intersection:
205// line1 = 10*[[9, 4], [5, 7]];
206// line2 = 10*[[2, 3], [6, 5]];
207// isect = line_intersection(line1, line2, SEGMENT, SEGMENT);
208SEGMENT = [true,true];
209
210
211// Constant: RAY
212// Topics: Constants, Lines
213// See Also: SEGMENT, LINE
214// Description: Treat a line as a ray, based at the first point. [true, false]
215// Example: Usage with line_intersection:
216// line = [[-30,0],[30,30]];
217// pt = [40,25];
218// closest = line_closest_point(line,pt,RAY);
219RAY = [true, false];
220
221
222// Constant: LINE
223// Topics: Constants, Lines
224// See Also: RAY, SEGMENT
225// Description: Treat a line as an unbounded line. [false, false]
226// Example: Usage with line_intersection:
227// line1 = 10*[[9, 4], [5, 7]];
228// line2 = 10*[[2, 3], [6, 5]];
229// isect = line_intersection(line1, line2, LINE, SEGMENT);
230LINE = [false, false];
231
232
233// Constant: IDENT
234// Description: Identity transformation matrix for three-dimensional transforms. Equal to `ident(4)`.
235IDENT=ident(4);
236
237
238// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap