2019-02-12 02:24:41 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2019-03-23 04:13:18 +00:00
|
|
|
// LibFile: constants.scad
|
2022-04-21 04:26:20 +00:00
|
|
|
// Constants for directions (used with anchoring), and for specifying line termination for
|
|
|
|
// use with geometry.scad.
|
2021-01-05 09:20:01 +00:00
|
|
|
// Includes:
|
2019-04-19 07:25:10 +00:00
|
|
|
// include <BOSL2/std.scad>
|
2022-04-21 04:26:20 +00:00
|
|
|
// FileSummary: Constants provided by the library
|
|
|
|
|
2019-02-12 02:24:41 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-04-14 20:32:47 +00:00
|
|
|
// a value that the user should never enter randomly;
|
|
|
|
// result of `dd if=/dev/random bs=32 count=1 |base64` :
|
|
|
|
_UNDEF="LRG+HX7dy89RyHvDlAKvb9Y04OTuaikpx205CTh8BSI";
|
2019-02-12 02:24:41 +00:00
|
|
|
|
2019-03-23 04:13:18 +00:00
|
|
|
// Section: General Constants
|
|
|
|
|
2019-07-18 01:57:23 +00:00
|
|
|
// Constant: $slop
|
2023-03-31 08:42:06 +00:00
|
|
|
// Synopsis: The slop amount to make printed items fit closely. `0.0` by default.
|
2023-03-31 08:30:09 +00:00
|
|
|
// Topics: Constants
|
2019-07-18 01:57:23 +00:00
|
|
|
// Description:
|
2021-02-23 02:54:46 +00:00
|
|
|
// A number of printers, particularly FDM/FFF printers, tend to be a bit sloppy in their printing.
|
|
|
|
// This has made it so that some parts won't fit together without adding a bit of extra slop space.
|
|
|
|
// That is what the `$slop` value is for. The value for this will vary from printer to printer.
|
|
|
|
// By default, we use a value of 0.00 so that parts should fit exactly for resin and other precision
|
|
|
|
// printers. This value is measured in millimeters. When making your own parts, you should add
|
|
|
|
// `$slop` to both sides of a hole that another part is to fit snugly into. For a loose fit, add
|
|
|
|
// `2*$slop` to each side. This should be done for both X and Y axes. The Z axis will require a
|
|
|
|
// slop that depends on your layer height and bridging settings, and hole sizes. We leave that as
|
|
|
|
// a more complicated exercise for the user.
|
2022-04-12 02:18:52 +00:00
|
|
|
// .
|
|
|
|
// Note that the slop value is accessed using the {{get_slop()}} function. This function provides
|
|
|
|
// the default value of 0 if you have not set `$slop`. This approach makes it possible for you to
|
|
|
|
// set `$slop` in your programs without experiencing peculiar OpenSCAD issues having to do with multiple
|
|
|
|
// definitions of the variable. If you write code that uses `$slop` be sure to reference it using {{get_slop()}}.
|
2021-02-23 02:54:46 +00:00
|
|
|
// DefineHeader(NumList): Calibration
|
|
|
|
// Calibration: To calibrate the `$slop` value for your printer, follow this procedure:
|
|
|
|
// Print the Slop Calibration part from the example below.
|
|
|
|
// Take the long block and orient it so the numbers are upright, facing you.
|
|
|
|
// Take the plug and orient it so that the arrow points down, facing you.
|
|
|
|
// Starting with the hole with the largest number in front of it, insert the small end of the plug into the hole.
|
|
|
|
// 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.
|
|
|
|
// Repeat step 5 until you have found the hole with the smallest number that the plug fits into without much force.
|
|
|
|
// The correct hole should hold the plug when the long block is turned upside-down.
|
|
|
|
// The number in front of that hole will indicate the `$slop` value that is ideal for your printer.
|
|
|
|
// Remember to set that slop value in your scripts after you include the BOSL2 library: ie: `$slop = 0.15;`
|
2021-02-23 03:48:03 +00:00
|
|
|
// Example(3D,Med): Slop Calibration Part.
|
2021-02-23 02:54:46 +00:00
|
|
|
// min_slop = 0.00;
|
|
|
|
// slop_step = 0.05;
|
|
|
|
// holes = 8;
|
|
|
|
// holesize = [15,15,15];
|
|
|
|
// height = 20;
|
|
|
|
// gap = 5;
|
|
|
|
// l = holes * (holesize.x + gap) + gap;
|
|
|
|
// w = holesize.y + 2*gap;
|
|
|
|
// h = holesize.z + 5;
|
|
|
|
// diff("holes")
|
|
|
|
// cuboid([l, w, h], anchor=BOT) {
|
|
|
|
// for (i=[0:holes-1]) {
|
|
|
|
// right((i-holes/2+0.5)*(holesize.x+gap)) {
|
|
|
|
// s = min_slop + slop_step * i;
|
2022-05-15 17:05:24 +00:00
|
|
|
// tag("holes") {
|
2021-02-23 02:54:46 +00:00
|
|
|
// cuboid([holesize.x + 2*s, holesize.y + 2*s, h+0.2]);
|
|
|
|
// fwd(w/2-1) xrot(90) linear_extrude(1.1) {
|
|
|
|
// text(
|
2022-01-11 01:22:11 +00:00
|
|
|
// text=format_fixed(s,2),
|
2021-02-23 02:54:46 +00:00
|
|
|
// size=0.4*holesize.x,
|
|
|
|
// halign="center",
|
2021-02-23 03:48:03 +00:00
|
|
|
// valign="center"
|
2021-02-23 02:54:46 +00:00
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// back(holesize.y*2.5) {
|
|
|
|
// difference() {
|
|
|
|
// union() {
|
|
|
|
// cuboid([holesize.x+10, holesize.y+10, 15], anchor=BOT);
|
|
|
|
// cuboid([holesize.x, holesize.y, 15+holesize.z], anchor=BOT);
|
|
|
|
// }
|
|
|
|
// up(3) fwd((holesize.y+10)/2) {
|
|
|
|
// prismoid([holesize.x/2,1], [0,1], h=holesize.y-6);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Example(2D): Where to add `$slop` gaps.
|
|
|
|
// $slop = 0.2;
|
|
|
|
// difference() {
|
|
|
|
// square([20,12],center=true);
|
|
|
|
// back(3) square([10+2*$slop,11],center=true);
|
|
|
|
// }
|
|
|
|
// back(8) {
|
|
|
|
// rect([15,5],anchor=FWD);
|
|
|
|
// rect([10,8],anchor=BACK);
|
|
|
|
// }
|
|
|
|
// color("#000") {
|
2021-02-23 03:40:08 +00:00
|
|
|
// arrow_path = [[5.1,6.1], [6.0,7.1], [8,7.1], [10.5,10]];
|
2021-02-23 02:54:46 +00:00
|
|
|
// xflip_copy()
|
2021-02-23 03:48:03 +00:00
|
|
|
// stroke(arrow_path, width=0.3, endcap1="arrow2");
|
2021-02-23 02:54:46 +00:00
|
|
|
// xcopies(21) back(10.5) {
|
2021-02-23 03:29:42 +00:00
|
|
|
// back(1.8) text("$slop", size=1.5, halign="center");
|
|
|
|
// text("gap", size=1.5, halign="center");
|
2021-02-23 02:54:46 +00:00
|
|
|
// }
|
|
|
|
// }
|
2022-04-12 02:18:52 +00:00
|
|
|
|
|
|
|
// Function: get_slop()
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: Returns the $slop value.
|
|
|
|
// Topics: Slop
|
|
|
|
// See Also: $slop
|
2022-04-12 02:18:52 +00:00
|
|
|
// Usage:
|
|
|
|
// slop = get_slop();
|
|
|
|
// Description:
|
|
|
|
// Returns the current $slop value, or the default value if the user did not set $slop.
|
|
|
|
// Always acess the `$slop` variable using this function.
|
|
|
|
function get_slop() = is_undef($slop) ? 0 : $slop;
|
2019-03-23 04:13:18 +00:00
|
|
|
|
|
|
|
|
2021-02-07 06:36:16 +00:00
|
|
|
// Constant: INCH
|
2023-03-31 08:42:06 +00:00
|
|
|
// Synopsis: A constant containing the number of millimeters in an inch. `25.4`
|
2023-03-31 08:30:09 +00:00
|
|
|
// Topics: Constants
|
2021-02-07 06:36:16 +00:00
|
|
|
// Description:
|
|
|
|
// The number of millimeters in an inch.
|
2022-01-21 05:07:52 +00:00
|
|
|
// Example(2D):
|
|
|
|
// square(2*INCH, center=true);
|
|
|
|
// Example(3D):
|
|
|
|
// cube([4,3,2.5]*INCH, center=true);
|
2021-02-07 06:36:16 +00:00
|
|
|
INCH = 25.4;
|
|
|
|
|
|
|
|
|
2019-03-23 04:13:18 +00:00
|
|
|
|
|
|
|
// Section: Directional Vectors
|
2019-04-23 03:55:03 +00:00
|
|
|
// Vectors useful for `rotate()`, `mirror()`, and `anchor` arguments for `cuboid()`, `cyl()`, etc.
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-04-19 06:32:17 +00:00
|
|
|
// Constant: LEFT
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The left-wards (X-) direction vector constant `[-1,0,0]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: RIGHT, FRONT, BACK, UP, DOWN, CENTER
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Vector pointing left. [-1,0,0]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
|
|
|
// cuboid(20, anchor=LEFT);
|
2019-04-19 06:32:17 +00:00
|
|
|
LEFT = [-1, 0, 0];
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-04-19 06:32:17 +00:00
|
|
|
// Constant: RIGHT
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The right-wards (X+) direction vector constant `[1,0,0]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: LEFT, FRONT, BACK, UP, DOWN, CENTER
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Vector pointing right. [1,0,0]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
|
|
|
// cuboid(20, anchor=RIGHT);
|
2019-04-19 06:32:17 +00:00
|
|
|
RIGHT = [ 1, 0, 0];
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-05-08 05:42:44 +00:00
|
|
|
// Constant: FRONT
|
2021-02-24 22:09:11 +00:00
|
|
|
// Aliases: FWD, FORWARD
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The front-wards (Y-) direction vector constant `[0,-1,0]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: LEFT, RIGHT, BACK, UP, DOWN, CENTER
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Vector pointing forward. [0,-1,0]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
2019-05-08 05:42:44 +00:00
|
|
|
// cuboid(20, anchor=FRONT);
|
|
|
|
FRONT = [ 0, -1, 0];
|
2021-02-24 22:09:11 +00:00
|
|
|
FWD = FRONT;
|
|
|
|
FORWARD = FRONT;
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-04-19 06:32:17 +00:00
|
|
|
// Constant: BACK
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The back-wards (Y+) direction vector constant `[0,1,0]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: LEFT, RIGHT, FRONT, UP, DOWN, CENTER
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Vector pointing back. [0,1,0]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
|
|
|
// cuboid(20, anchor=BACK);
|
2019-04-19 06:32:17 +00:00
|
|
|
BACK = [ 0, 1, 0];
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-05-08 05:42:44 +00:00
|
|
|
// Constant: BOTTOM
|
2021-11-11 04:12:14 +00:00
|
|
|
// Aliases: BOT, DOWN
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The down-wards (Z-) direction vector constant `[0,0,-1]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: LEFT, RIGHT, FRONT, BACK, UP, CENTER
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Vector pointing down. [0,0,-1]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
2019-05-08 05:42:44 +00:00
|
|
|
// cuboid(20, anchor=BOTTOM);
|
|
|
|
BOTTOM = [ 0, 0, -1];
|
2021-02-24 22:09:11 +00:00
|
|
|
BOT = BOTTOM;
|
|
|
|
DOWN = BOTTOM;
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-05-08 05:42:44 +00:00
|
|
|
// Constant: TOP
|
2021-02-24 22:09:11 +00:00
|
|
|
// Aliases: UP
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The top-wards (Z+) direction vector constant `[0,0,1]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: LEFT, RIGHT, FRONT, BACK, DOWN, CENTER
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Vector pointing up. [0,0,1]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
2019-05-08 05:42:44 +00:00
|
|
|
// cuboid(20, anchor=TOP);
|
|
|
|
TOP = [ 0, 0, 1];
|
2021-02-24 22:09:11 +00:00
|
|
|
UP = TOP;
|
2019-02-27 11:46:40 +00:00
|
|
|
|
2019-04-19 06:32:17 +00:00
|
|
|
// Constant: CENTER
|
2022-01-21 05:07:52 +00:00
|
|
|
// Aliases: CTR, CENTRE
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: The center vector constant `[0,0,0]`.
|
2021-03-02 06:44:00 +00:00
|
|
|
// Topics: Constants, Vectors
|
2021-11-12 03:46:39 +00:00
|
|
|
// See Also: LEFT, RIGHT, FRONT, BACK, UP, DOWN
|
2019-03-23 04:13:18 +00:00
|
|
|
// Description: Zero vector. Centered. [0,0,0]
|
2019-04-23 03:55:03 +00:00
|
|
|
// Example(3D): Usage with `anchor`
|
2019-05-10 11:02:58 +00:00
|
|
|
// cuboid(20, anchor=CENTER);
|
2019-04-19 06:32:17 +00:00
|
|
|
CENTER = [ 0, 0, 0]; // Centered zero vector.
|
2021-02-24 22:09:11 +00:00
|
|
|
CTR = CENTER;
|
2022-01-21 05:07:52 +00:00
|
|
|
CENTRE = CENTER;
|
2019-03-23 04:13:18 +00:00
|
|
|
|
|
|
|
|
2022-01-07 19:23:01 +00:00
|
|
|
// Section: Line specifiers
|
|
|
|
// Used by functions in geometry.scad for specifying whether two points
|
|
|
|
// are treated as an unbounded line, a ray with one endpoint, or a segment
|
|
|
|
// with two endpoints.
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2021-09-09 22:32:58 +00:00
|
|
|
// Constant: SEGMENT
|
2023-03-31 08:42:06 +00:00
|
|
|
// Synopsis: A constant for specifying a line segment in various geometry.scad functions. `[true,true]`
|
2021-09-09 22:32:58 +00:00
|
|
|
// Topics: Constants, Lines
|
|
|
|
// See Also: RAY, LINE
|
|
|
|
// Description: Treat a line as a segment. [true, true]
|
|
|
|
// Example: Usage with line_intersection:
|
|
|
|
// line1 = 10*[[9, 4], [5, 7]];
|
|
|
|
// line2 = 10*[[2, 3], [6, 5]];
|
|
|
|
// isect = line_intersection(line1, line2, SEGMENT, SEGMENT);
|
|
|
|
SEGMENT = [true,true];
|
|
|
|
|
|
|
|
|
|
|
|
// Constant: RAY
|
2023-03-31 08:42:06 +00:00
|
|
|
// Synopsis: A constant for specifying a ray line in various geometry.scad functions. `[true,false]`
|
2021-09-09 22:32:58 +00:00
|
|
|
// Topics: Constants, Lines
|
|
|
|
// See Also: SEGMENT, LINE
|
|
|
|
// Description: Treat a line as a ray, based at the first point. [true, false]
|
|
|
|
// Example: Usage with line_intersection:
|
|
|
|
// line = [[-30,0],[30,30]];
|
|
|
|
// pt = [40,25];
|
|
|
|
// closest = line_closest_point(line,pt,RAY);
|
|
|
|
RAY = [true, false];
|
|
|
|
|
|
|
|
|
|
|
|
// Constant: LINE
|
2023-03-31 08:42:06 +00:00
|
|
|
// Synopsis: A constant for specifying an unbounded line in various geometry.scad functions. `[false,false]`
|
2021-09-09 22:32:58 +00:00
|
|
|
// Topics: Constants, Lines
|
|
|
|
// See Also: RAY, SEGMENT
|
|
|
|
// Description: Treat a line as an unbounded line. [false, false]
|
|
|
|
// Example: Usage with line_intersection:
|
|
|
|
// line1 = 10*[[9, 4], [5, 7]];
|
|
|
|
// line2 = 10*[[2, 3], [6, 5]];
|
|
|
|
// isect = line_intersection(line1, line2, LINE, SEGMENT);
|
|
|
|
LINE = [false, false];
|
|
|
|
|
|
|
|
|
2022-03-26 03:35:07 +00:00
|
|
|
// Constant: IDENT
|
2023-03-31 08:30:09 +00:00
|
|
|
// Synopsis: A constant containing the 3D identity transformation matrix.
|
|
|
|
// Topics: Affine, Matrices, Transforms
|
|
|
|
// See Also: ident()
|
2022-03-26 03:35:07 +00:00
|
|
|
// Description: Identity transformation matrix for three-dimensional transforms. Equal to `ident(4)`.
|
|
|
|
IDENT=ident(4);
|
|
|
|
|
|
|
|
|
2020-05-30 02:04:34 +00:00
|
|
|
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|