Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Adrian Mariano 2020-05-25 23:45:37 -04:00
commit c25d6eb938
8 changed files with 283 additions and 257 deletions

View file

@ -19,8 +19,8 @@ LibFile blocks can be followed by multiple lines that can be added as markdown t
// You just need to make sure that each line is indented, with
// at least three spaces after the comment marker. You can
// denote a paragraph break with a comment line with three
// trailing spaces.
//
// trailing spaces, or just a period.
// .
// The end of the block is denoted by a line without a comment.
```
@ -33,12 +33,12 @@ Sections can also include Figures; images generated from code that is not shown
```
// Section: Foobar
// You can have several lines of markdown formatted text here.
// You just need to make sure that each line is indented with
// You just need to make sure that each line is indented, with
// at least three spaces after the comment marker. You can
// denote a paragraph break with a comment line with three
// trailing spaces.
//
// The end of the block is denoted by a line without a comment,
// trailing spaces, or just a period.
// .
// The end of the block is denoted by a line without a comment.
// or a line that is unindented after the comment.
// Figure: Figure description
// cylinder(h=100, d1=75, d2=50);
@ -70,25 +70,28 @@ Valid sub-blocks are:
- `Status: DEPRECATED, use blah instead.` - Optional, used to denote deprecation.
- `Usage: Optional Usage Title` - Optional. Multiple allowed. Followed by an indented block of usage patterns. Optional arguments should be in braces like `[opt]`. Alternate args should be separated by a vertical bar like `r|d`.
- `Description:` - Can be single-line or a multi-line block of the description.
- `Figure: Optional Figure Title` - Optional. Multiple allowed. Followed by a multi-line code block used to create a figure image. The code will not be shown. All figures will follow the Description block.
- `Arguments:` - Denotes start of an indented block of argument descriptions. Each line has the argument name, a space, an equals, another space, then the description for the argument all on one line. Like `arg = The argument description`. If you really need to explain an argument in longer form, explain it in the Description.
- `Side Effects:` - Denotes the start of a block describing the side effects, such as `$special_var`s that are set.
- `Extra Anchors:` - Denotes the start of an indented block of available non-standard named anchors for a part.
- `Example:` - Denotes the beginning of a multi-line example code block.
- `Examples:` - Denotes the beginning of a block of examples, where each line will be shows as a separate example with a separate image if needed.
Modules blocks will generate images for each example block. Function and Constant blocks will only generate images for example blocks if they have `2D` or `3D` tags. Example blocks can have tags added by putting then inside parentheses before the colon. Ie: `Examples(BigFlatSpin):`.
Modules blocks will generate images for each example or figure block. Function and Constant blocks will only generate images for example blocks if they have `2D` or `3D` tags. Example and figure blocks can have tags added by putting then inside parentheses before the colon. Ie: `Examples(BigFlatSpin):` or `Figure(2D):`.
The full set of optional example tags are:
- `2D`: Orient camera in a top-down view for showing 2D objects.
- `3D`: Orient camera in an oblique view for showing 3D objects. Used to force an Example sub-block to generate an image in Function and Constant blocks.
- `Spin`: Animate camera orbit around the `[0,1,1]` axis to display all sides of an object.
- `FlatSpin`: Animate camera orbit around the Z axis, above the XY plane.
- `Edges`: Highlight face edges.
- `FR`: Force full rendering from OpenSCAD, instead of the normal preview.
- `NORENDER`: Don't generate an image for this example.
- `Small`: Make the image small sized. (The default)
- `Med`: Make the image medium sized.
- `Big`: Make the image big sized.
- `Huge`: Make the image huge sized.
- `Spin`: Animate camera orbit around the `[0,1,1]` axis to display all sides of an object.
- `FlatSpin`: Animate camera orbit around the Z axis, above the XY plane.
- `FR`: Force full rendering from OpenSCAD, instead of the normal preview.
- `Edges`: Highlight face edges.
Indentation is important, as it denotes the end of sub-block.
@ -105,12 +108,19 @@ Indentation is important, as it denotes the end of sub-block.
// A longer, multi-line description.
// All description blocks are added together.
// You _can_ use *markdown* notation as well.
// You can have paragraph breaks by having a blank line with
// only enough trailing spaces to match indentation like this:
//
// You can have paragraph breaks by having a
// line with just a period, like this:
// .
// You can end multi-line blocks by un-indenting the next
// line, or by using a comment with no spaces like this:
//
// Figure: Figure description
// cylinder(h=100, d1=75, d2=50);
// up(100) cylinder(h=100, d1=50, d2=75);
// Figure(Spin): Animated figure that spins to show all faces.
// cube([10,100,50], center=true);
// cube([100,10,30], center=true);
//
// Arguments:
// foo = This is the description of the foo argument. All on one line.
// bar = This is the description of the bar argument. All on one line.

View file

@ -1,9 +1,10 @@
include <BOSL2/std.scad>
include <BOSL2/hull.scad>
$fn=32;
cuboid([60,40,40], rounding=5, edges=edges("Z"), anchor=BOTTOM) {
attach(TOP, BOTTOM) rounded_prismoid([60,40],[20,20], h=50, r1=5, r2=10) {
attach(TOP, BOTTOM) prismoid([60,40],[20,20], h=50, rounding1=5, rounding2=10) {
attach(TOP) cylinder(d=20, h=30, center=false) {
attach(TOP) cylinder(d1=50, d2=30, h=12, center=false);
}

View file

@ -1070,9 +1070,9 @@ function find_circle_3points(pt1, pt2, pt3) =
// Function: find_circle_tangents()
// Function: circle_point_tangents()
// Usage:
// tangents = find_circle_tangents(r|d, cp, pt);
// tangents = circle_point_tangents(r|d, cp, pt);
// Description:
// Given a circle and a point outside that circle, finds the tangent point(s) on the circle for a
// line passing through the point. Returns list of zero or more sublists of [ANG, TANGPT]
@ -1083,12 +1083,12 @@ function find_circle_3points(pt1, pt2, pt3) =
// pt = The coordinates of the external point.
// Example(2D):
// cp = [-10,-10]; r = 30; pt = [30,10];
// tanpts = subindex(find_circle_tangents(r=r, cp=cp, pt=pt),1);
// tanpts = subindex(circle_point_tangents(r=r, cp=cp, pt=pt),1);
// color("yellow") translate(cp) circle(r=r);
// color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);}
// color("red") move_copies(tanpts) circle(d=3,$fn=12);
// color("blue") move_copies([cp,pt]) circle(d=3,$fn=12);
function find_circle_tangents(r, d, cp, pt) =
function circle_point_tangents(r, d, cp, pt) =
assert(is_num(r) || is_num(d))
assert(is_vector(cp))
assert(is_vector(pt))
@ -1124,8 +1124,8 @@ function find_circle_tangents(r, d, cp, pt) =
// c1 = [3,4]; r1 = 2;
// c2 = [7,10]; r2 = 3;
// pts = circle_circle_tangents(c1,r1,c2,r2);
// stroke(move(c1,p=circle(r=r1)),width=.1,closed=true);
// stroke(move(c2,p=circle(r=r2)),width=.1,closed=true);
// move(c1) stroke(circle(r=r1), width=.1, closed=true);
// move(c2) stroke(circle(r=r2), width=.1, closed=true);
// colors = ["green","black","blue","red"];
// for(i=[0:len(pts)-1]) color(colors[i]) stroke(pts[i],width=.1);
// Example(2D): Circles overlap so only exterior tangents exist.
@ -1133,8 +1133,8 @@ function find_circle_tangents(r, d, cp, pt) =
// c1 = [4,4]; r1 = 3;
// c2 = [7,7]; r2 = 2;
// pts = circle_circle_tangents(c1,r1,c2,r2);
// stroke(move(c1,p=circle(r=r1)),width=.1,closed=true);
// stroke(move(c2,p=circle(r=r2)),width=.1,closed=true);
// move(c1) stroke(circle(r=r1), width=.1, closed=true);
// move(c2) stroke(circle(r=r2), width=.1, closed=true);
// colors = ["green","black","blue","red"];
// for(i=[0:len(pts)-1]) color(colors[i]) stroke(pts[i],width=.1);
// Example(2D): Circles are tangent. Only exterior tangents are returned. The degenerate internal tangent is not returned.
@ -1142,8 +1142,8 @@ function find_circle_tangents(r, d, cp, pt) =
// c1 = [4,4]; r1 = 4;
// c2 = [4,10]; r2 = 2;
// pts = circle_circle_tangents(c1,r1,c2,r2);
// stroke(move(c1,p=circle(r=r1)),width=.1,closed=true);
// stroke(move(c2,p=circle(r=r2)),width=.1,closed=true);
// move(c1) stroke(circle(r=r1), width=.1, closed=true);
// move(c2) stroke(circle(r=r2), width=.1, closed=true);
// colors = ["green","black","blue","red"];
// for(i=[0:1:len(pts)-1]) color(colors[i]) stroke(pts[i],width=.1);
// Example(2D): One circle is inside the other: no tangents exist. If the interior circle is tangent the single degenerate tangent will not be returned.
@ -1151,22 +1151,32 @@ function find_circle_tangents(r, d, cp, pt) =
// c1 = [4,4]; r1 = 4;
// c2 = [5,5]; r2 = 2;
// pts = circle_circle_tangents(c1,r1,c2,r2);
// stroke(move(c1,p=circle(r=r1)),width=.1,closed=true);
// stroke(move(c2,p=circle(r=r2)),width=.1,closed=true);
// echo(pts); // Returns []
// move(c1) stroke(circle(r=r1), width=.1, closed=true);
// move(c2) stroke(circle(r=r2), width=.1, closed=true);
// echo(pts); // Returns []
function circle_circle_tangents(c1,r1,c2,r2,d1,d2) =
let(
r1 = get_radius(r1=r1,d1=d1),
r2 = get_radius(r1=r2,d1=d2),
Rvals = [r2-r1, r2-r1, -r2-r1, -r2-r1]/norm(c1-c2),
kvals = [-1,1,-1,1],
ext = [1,1,-1,-1],
N = 1-sqr(Rvals[2])>=0 ? 4 :
1-sqr(Rvals[0])>=0 ? 2 : 0,
coef= [for(i=[0:1:N-1]) [[Rvals[i], -kvals[i]*sqrt(1-sqr(Rvals[i]))],
[kvals[i]*sqrt(1-sqr(Rvals[i])), Rvals[i]]]*unit(c2-c1)]
)
[for(i=[0:1:N-1]) let(pt=[c1-r1*coef[i], c2-ext[i]*r2*coef[i]]) if (pt[0]!=pt[1]) pt];
let(
r1 = get_radius(r1=r1,d1=d1),
r2 = get_radius(r1=r2,d1=d2),
Rvals = [r2-r1, r2-r1, -r2-r1, -r2-r1]/norm(c1-c2),
kvals = [-1,1,-1,1],
ext = [1,1,-1,-1],
N = 1-sqr(Rvals[2])>=0 ? 4 :
1-sqr(Rvals[0])>=0 ? 2 : 0,
coef= [
for(i=[0:1:N-1]) [
[Rvals[i], -kvals[i]*sqrt(1-sqr(Rvals[i]))],
[kvals[i]*sqrt(1-sqr(Rvals[i])), Rvals[i]]
] * unit(c2-c1)
]
) [
for(i=[0:1:N-1]) let(
pt = [
c1-r1*coef[i],
c2-ext[i]*r2*coef[i]
]
) if (pt[0]!=pt[1]) pt
];

View file

@ -1,8 +1,17 @@
include<std.scad>
include<structs.scad>
include<threading.scad>
include<phillips_drive.scad>
include<torx_drive.scad>
//////////////////////////////////////////////////////////////////////
// LibFile: screws.scad
// Functions and modules for creating metric and UTS standard screws and nuts.
// To use, add the following lines to the beginning of your file:
// ```
// include <BOSL2/std.scad>
// include <BOSL2/screws.scad>
// ```
//////////////////////////////////////////////////////////////////////
include <structs.scad>
include <threading.scad>
include <phillips_drive.scad>
include <torx_drive.scad>
/*
http://mdmetric.com/thddata.htm#idx
@ -16,7 +25,7 @@ Torx values: https://www.stanleyengineeredfastening.com/-/media/web/sef/resourc
*/
function parse_screw_name(name) =
function _parse_screw_name(name) =
let( commasplit = str_split(name,","),
length = str_num(commasplit[1]),
xdash = str_split(commasplit[0], "-x"),
@ -30,12 +39,12 @@ function parse_screw_name(name) =
let(val=str_num(type))
val == floor(val) && val>=0 && val<=12 ? str("#",type) : val
)
["english", diam, thread, 25.4*length];
["english", diam, thread, 25.4*length];
// drive can be "hex", "phillips", "slot", "torx", or "none"
// or you can specify "ph0" up to "ph4" for phillips and "t20" for torx 20
function parse_drive(drive=undef, drive_size=undef) =
function _parse_drive(drive=undef, drive_size=undef) =
is_undef(drive) ? ["none",undef] :
let(drive = downcase(drive))
in_list(drive,["hex","phillips", "slot", "torx", "phillips", "none"]) ? [drive, drive_size] :
@ -43,116 +52,102 @@ function parse_drive(drive=undef, drive_size=undef) =
substr(drive,0,2)=="ph" ? ["phillips", str_int(substr(drive,2))] :
assert(str("Unknown screw drive type ",drive));
// Function: screw_info()
// Usage:
// info = screw_info(name, [head], [thread], [drive], [drive_size], [oversize])
//
// Description:
// Look up screw characteristics for the specified screw type.
//
// For metric (ISO) `name` is M<size>x<pitch>,<length>, e.g. `"M6x1,10"` specifies a 6mm diameter screw with a thread pitch of 1mm and length of 10mm.
// You can omit the pitch or length, e.g. `"M6x1"`, or `"M6,10"`, or just `"M6"`.
//
// For English (UTS) name is <size>-<threadcount>,<length>, e.g. `"#8-32,1/2"`, or `"1/4-20,1"`. Units are in inches, including the length.
// Size can be a number from 0 to 12 with or without a leading '#' to specify a screw gauge size, or any other value to specify
// a diameter in inches, either as a float or a fraction, so `"0.5-13"` and `"1/2-13"` are equivalent. To force interpretation of the value
// as inches add `''` to the end, e.g. `"1''-4"` is a one inch screw and `"1-80"` is a very small 1-gauge screw. The pitch is specified
// using a thread count, the number of threads per inch. The length is in inches.
//
// If you omit the pitch then a standard screw pitch will be supplied from lookup tables for the screw diameter you have chosen.
// For each screw diameter, multiple standard pitches are possible.
// For the UTS system these the availble thread types are:
// - "coarse" or "UNC"
// - "fine" or "UNF"
// - "extra fine", "extrafine" or "UNEF".
// The ISO system defines a coarse threading and three different fine threadings but does not give different names to the fine threadings.
// The thread options for ISO are:
// - "coarse"
// - "fine"
// - "extra fine" or "extrafine"
// - "super fine" or "superfine"
// The default pitch selection is "coarse". Note that this selection is case independent. Set
// `thread` to one of these values to choose a different pitch. Note that not every pitch category is defined at every
// diameter. You can also specify the thread pitch directly, for example you could set `thread=2` which would
// produce threads with a pitch of 2mm. The final option is to specify `thread="none"` to produce an unthreaded
// screw either to simplify the model or to use for cutting out screw holes. Setting the pitch to zero also produces
// an unthreaded screw. If you specify a numeric thread value it will override any value given in `name`.
//
// The `head` parameter specifies the type of head the screw will have. Options for the head are
// - "flat"
// - "flat small"
// - "flat large"
// - "flat undercut"
// - "round"
// - "pan"
// - "pan flat"
// - "pan round"
// - "socket"
// - "hex"
// - "button"
// - "cheese"
// - "fillister"
// - "none"
// Note that different sized flat heads exist for the same screw type. Sometimes this depends on the type of recess. If you specify "flat" then
// the size will be chosen appropriately for the recess you specify. The default is "none".
//
// The `drive` parameter specifies the recess type. Options for the drive are
// - "none"
// - "phillips"
// - "slot"
// - "torx"
// - "hex"
// - "ph0", up to "ph4" for phillips of the specified size
// - "t<size>" for torx at a specified size, e.g. "t20"
// The default drive is "none"
//
// Only some combinations of head and drive type are supported. Supported UTS (English) head and drive combinations:
//
// Head| Drive
// ---|---
// none | hex, torx
// hex |
// socket | hex, torx
// button | hex, torx
// round | slot, phillips
// fillister | slot, phillips
// flat | slot, phillips, hex, torx
// flat small | phillips, slot
// flat large | hex, torx
// flat undercut| slot, phillips
//
// Supported metric head and drive combinations:
//
// Head| Drive
// ---|---
// none |hex, torx
// hex |
// socket| hex, torx
// pan | slot, phillips
// button| hex, torx
// cheese| slot, phillips
// flat | phillips, slot, hex, torx
//
// The drive size is specified appropriately to the drive type: drive number for phillips or torx, and allen width in mm or inches (as appropriate) for hex.
// Drive size is determined automatically from the screw size, but by passing the `drive_size` parameter
// you can override the default, or in cases where no default exists you can specify it.
//
// The `oversize` parameter adds the specified amount to the screw and head diameter to make an oversized screw.
// This is intended for generating clearance holes, not for dealing with printer inaccuracy. Does not affect length, thread pitch or head height.
//
// The output is a structure with the following fields:
// - system: either "UTS" or "ISO" (used for correct tolerance computation)
// - diameter: the nominal diameter of the screw shaft in mm
// - pitch: the thread pitch in mm
// - head: the type of head (a string from the list above)
// - head_size: size of the head in mm
// - head_angle: countersink angle for flat heads
// - head_height: height of the head (when needed to specify the head)
// - drive: the drive type ("phillips", "torx", "slot", "hex", "none")
// - drive_size: the drive size, either a drive number (phillips or torx) or a dimension in mm (hex). Not defined for slot drive
// - drive_diameter: diameter of a phillips drive
// - drive_width: width of the arms of the cross in a phillips drive or the slot for a slot drive
// - drive_depth: depth of the drive recess
// - length: length of the screw in mm measured in the customary fashion: for flat head screws the total length and for other screws, the length from the bottom of the head to the screw tip.
// .
// For metric (ISO) the `name=` argument is formatted in a string like: `"M<size>x<pitch>,<length>"`.
// e.g. `"M6x1,10"` specifies a 6mm diameter screw with a thread pitch of 1mm and length of 10mm.
// You can omit the pitch or length, e.g. `"M6x1"`, or `"M6,10"`, or just `"M6"`.
// .
// For English (UTS) `name=` is a string like `"<size>-<threadcount>,<length>"`.
// e.g. `"#8-32,1/2"`, or `"1/4-20,1"`. Units are in inches, including the length. Size can be a
// number from 0 to 12 with or without a leading `#` to specify a screw gauge size, or any other
// value to specify a diameter in inches, either as a float or a fraction, so `"0.5-13"` and
// `"1/2-13"` are equivalent. To force interpretation of the value as inches add `''` (two
// single-quotes) to the end, e.g. `"1''-4"` is a one inch screw and `"1-80"` is a very small
// 1-gauge screw. The pitch is specified using a thread count, the number of threads per inch.
// The length is in inches.
// .
// If you omit the pitch then a standard screw pitch will be supplied from lookup tables for the
// screw diameter you have chosen. For each screw diameter, multiple standard pitches are possible.
// The available thread pitch types are:
// - `"coarse"`
// - `"fine"`
// - `"extrafine"` or `"extra fine"`
// - `"superfine"` or `"super fine"` (Metric/ISO only.)
// - `"UNC"` (English/UTS only. Same as `"coarse"`.)
// - `"UNF"` (English/UTS only. Same as `"fine"`.)
// - `"UNEF"` (English/UTS only. Same as `"extrafine"`.)
// .
// The default pitch selection is `"coarse"`. Note that this selection is case insensitive. Set the
// `thread=` argument to one of these values to choose a different pitch. Note that not every pitch
// category is defined at every diameter. You can also specify the thread pitch directly, for example
// you could set `thread=2` which would produce threads with a pitch of 2mm. The final option is to
// specify `thread="none"` to produce an unthreaded screw either to simplify the model or to use for
// cutting out screw holes. Setting the pitch to `0` (zero) also produces an unthreaded screw.
// If you specify a numeric thread value it will override any value given in the `name=` argument.
// .
// The `head=` parameter specifies the type of head the screw will have. Options for the head are
// `"flat"`, `"flat small"`, `"flat large"`, `"flat undercut"`, `"round"`, `"pan"`, `"pan flat"`,
// `"pan round"`, `"socket"`, `"hex"`, `"button"`, `"cheese"`, `"fillister"`, or `"none"`
// .
// Note that different sized flat heads exist for the same screw type. Sometimes this depends on
// the type of recess. If you specify `"flat"` then the size will be chosen appropriately for the
// recess you specify. The default is `"none"`.
// .
// The `drive=` argument specifies the recess type. Options for the drive are `"none"`, `"hex"`,
// `"slot"`, `"phillips"`, `"ph0"` to `"ph4"` (for phillips of the specified size), `"torx"` or
// `"t<size>"` (for Torx at a specified size, e.g. `"t20"`). The default drive is `"none"`
// .
// Only some combinations of head and drive type are supported:
// .
// Head | Drive
// ----------------- | ----------------------------
// `"none"` | hex, torx
// `"hex"` | *none*
// `"socket"` | hex, torx
// `"button"` | hex, torx
// `"flat"` | slot, phillips, hex, torx
// `"round"` | slot, phillips (UTS/English only.)
// `"fillister"` | slot, phillips (UTS/English only.)
// `"flat small"` | phillips, slot (UTS/English only.)
// `"flat large"` | hex, torx (UTS/English only.)
// `"flat undercut"` | slot, phillips (UTS/English only.)
// `"pan"` | slot, phillips (ISO/Metric only.)
// `"cheese"` | slot, phillips (ISO/Metric only.)
// .
// The drive size is specified appropriately to the drive type: drive number for phillips or torx,
// and allen width in mm or inches (as appropriate) for hex. Drive size is determined automatically
// from the screw size, but by passing the `drive_size=` argument you can override the default, or
// in cases where no default exists you can specify it.
// .
// The `oversize=` parameter adds the specified amount to the screw and head diameter to make an
// oversized screw. This is intended for generating clearance holes, not for dealing with printer
// inaccuracy. Does not affect length, thread pitch or head height.
// .
// The output is a [[struct|structs.scad]] with the following fields:
// .
// Field | What it is
// ------------------ | ---------------
// `"system"` | Either `"UTS"` or `"ISO"` (used for correct tolerance computation).
// `"diameter"` | The nominal diameter of the screw shaft in mm.
// `"pitch"` | The thread pitch in mm.
// `"head"` | The type of head (a string from the list above).
// `"head_size"` | Size of the head in mm.
// `"head_angle"` | Countersink angle for flat heads.
// `"head_height"` | Height of the head (when needed to specify the head).
// `"drive"` | The drive type (`"phillips"`, `"torx"`, `"slot"`, `"hex"`, `"none"`)
// `"drive_size"` | The drive size, either a drive number (phillips or torx) or a dimension in mm (hex). Not defined for slot drive.
// `"drive_diameter"` | Diameter of a phillips drive.
// `"drive_width"` | Width of the arms of the cross in a phillips drive or the slot for a slot drive.
// `"drive_depth"` | Depth of the drive recess.
// `"length"` | Length of the screw in mm measured in the customary fashion. For flat head screws the total length and for other screws, the length from the bottom of the head to the screw tip.
//
// Arguments:
// name = screw specification, e.g. "M5x1" or "#8-32"
// head = head type (see list above). Default: none
@ -161,10 +156,10 @@ function parse_drive(drive=undef, drive_size=undef) =
// drive_size = size of drive recess to override computed value
// oversize = amount to increase screw diameter for clearance holes. Default: 0
function screw_info(name, head, thread="coarse", drive, drive_size=undef, oversize=0) =
let(type=parse_screw_name(name),
drive_info = parse_drive(drive, drive_size),
let(type=_parse_screw_name(name),
drive_info = _parse_drive(drive, drive_size),
drive=drive_info[0],
screwdata =
screwdata =
type[0] == "english" ? _screw_info_english(type[1],type[2], head, thread, drive) :
type[0] == "metric" ? _screw_info_metric(type[1], type[2], head, thread, drive) :
[],
@ -176,7 +171,7 @@ function screw_info(name, head, thread="coarse", drive, drive_size=undef, oversi
)
)
struct_set(screwdata, over_ride);
function _screw_info_english(diam, threadcount, head, thread, drive) =
let(
@ -223,7 +218,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
]
)
inch / struct_val(UTS_thread, diam)[tind],
head_data =
head_data =
head=="none" || is_undef(head) ? let (
UTS_setscrew = [ // hex width, hex depth
["#0", [0.028, 0.050]],
@ -278,7 +273,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
[1.25, [ 1+7/8, 27/32]],
[1.5, [ 2.25, 15/16]],
[1.75, [ 2+5/8, 1+3/32]],
[2, [ 3, 1+7/32]],
[2, [ 3, 1+7/32]],
],
entry = struct_val(UTS_hex, diam)
)
@ -289,7 +284,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
["#0", [ 0.096, 0.05, 6, 0.025, 0.027]],
["#1", [ 0.118, 1/16, 7, 0.031, 0.036]],
["#2", [ 9/64, 5/64, 8, 0.038, 0.037]],
["#3", [ 0.161, 5/64, 8, 0.044, 0.041]], // For larger sizes, recess depth is
["#3", [ 0.161, 5/64, 8, 0.044, 0.041]], // For larger sizes, recess depth is
["#4", [ 0.183, 3/32, 10, 0.051, 0.049]], // half the diameter
["#5", [ 0.205, 3/32, 10, 0.057, 0.049]],
["#6", [ 0.226, 7/64, 15, 0.064, 0.058]],
@ -318,7 +313,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
drive_size = drive=="hex" ? [["drive_size",inch*entry[1]], ["drive_depth",inch*hexdepth]] :
drive=="torx" ? [["drive_size",entry[2]],["drive_depth",inch*entry[4]]] : []
)
concat([["head","socket"],["head_size",inch*entry[0]], ["head_height", inch*diameter]],drive_size) :
concat([["head","socket"],["head_size",inch*entry[0]], ["head_height", inch*diameter]],drive_size) :
head=="pan" ? let (
UTS_pan = [ // pan head for phillips or slotted
// diam, head ht slotted, head height phillips, phillips drive, phillips diam, phillips width, phillips depth, slot width, slot depth
@ -340,7 +335,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
entry = struct_val(UTS_pan, diam),
drive_size = drive=="phillips" ? [["drive_size", entry[3]], ["drive_diameter",inch*entry[4]],["drive_width",inch*entry[5]],["drive_depth",inch*entry[6]]] :
[["drive_width", inch*entry[7]], ["drive_depth",inch*entry[8]]])
concat([["head","pan"], ["head_size", inch*entry[0]], ["head_height", inch*entry[htind]]], drive_size) :
concat([["head","pan"], ["head_size", inch*entry[0]], ["head_height", inch*entry[htind]]], drive_size) :
head=="button" || head=="round" ? let(
UTS_button = [ // button, hex or torx drive
// head diam, height, phillips, hex, torx, hex depth
@ -358,7 +353,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
[5/16, [0.547, 0.166, undef, 3/16, 40 , 0.105, 0.090]],
[3/8, [0.656, 0.199, undef, 7/32, 45 , 0.122, 0.106]],
[7/16, [0.750, 0.220, undef, 1/4, undef, 0.193, undef]], // hex depth interpolated
[1/2, [0.875, 0.265, undef, 5/16, 55 , 0.175, 0.158]],
[1/2, [0.875, 0.265, undef, 5/16, 55 , 0.175, 0.158]],
[5/8, [1.000, 0.331, undef, 3/8, 60, , 0.210, 0.192]],
[3/4, [1.1, 0.375, undef, 7/16, undef, 0.241]], // hex depth extrapolated
],
@ -424,7 +419,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
["#2", [ .162, 1, 6 , 0.036, 0.096, 0.055, 0.017, 0.031, 0.023, 0.088, 0.048, 0.017, 0.016]],
["#3", [ .187, 1, undef, 0.042, 0.100, 0.060, 0.018, 0.035, 0.027, 0.099, 0.059, 0.018, 0.019]],
["#4", [ .212, 1, 8 , 0.047, 0.122, 0.081, 0.018, 0.039, 0.030, 0.110, 0.070, 0.018, 0.022]],
["#5", [ .237, 2, undef, 0.053, 0.148, 0.074, 0.027, 0.043, 0.034, 0.122, 0.081, 0.018, 0.024]], // ph#1 for undercut
["#5", [ .237, 2, undef, 0.053, 0.148, 0.074, 0.027, 0.043, 0.034, 0.122, 0.081, 0.018, 0.024]], // ph#1 for undercut
["#6", [ .262, 2, 10 , 0.059, 0.168, 0.094, 0.029, 0.048, 0.038, 0.140, 0.066, 0.025, 0.027]],
["#8", [ .312, 2, 15 , 0.070, 0.182, 0.110, 0.030, 0.054, 0.045, 0.168, 0.094, 0.029, 0.032]],
["#10",[ .362, 2, 20 , 0.081, 0.198, 0.124, 0.032, 0.060, 0.053, 0.182, 0.110, 0.030, 0.037]],
@ -492,7 +487,7 @@ function _screw_info_english(diam, threadcount, head, thread, drive) =
function _screw_info_metric(diam, pitch, head, thread, drive) =
let(
a=echo(metricsi=diam,pitch,head,thread,drive),
pitch = is_num(thread) ? thread :
pitch = is_num(thread) ? thread :
is_def(pitch) ? pitch :
let(
tind=struct_val([["coarse",0],
@ -596,7 +591,7 @@ function _screw_info_metric(diam, pitch, head, thread, drive) =
metric_socket = [ // height = screw diameter
//diam, hex
[1.4, [2.5, 1.3]],
[1.6, [3, 1.5]],
[1.6, [3, 1.5]],
[2, [3.8, 1.5, 6, 0.77]],
[2.5, [4.5, 2, 8, 1.05]],
[2.6, [5, 2, 8, 1.05]],
@ -620,14 +615,14 @@ function _screw_info_metric(diam, pitch, head, thread, drive) =
[33, [50, 24]],
[36, [54, 27]],
[42, [63, 32]],
[48, [72, 36]],
[48, [72, 36]],
],
entry = struct_val(metric_socket, diam),
drive_size = drive=="hex" ? [["drive_size",entry[1]],["drive_depth",diam/2]] :
drive=="torx" ? [["drive_size", entry[2]], ["drive_depth", entry[3]]] :
[]
)
concat([["head","socket"],["head_size",entry[0]], ["head_height", diam]],drive_size) :
concat([["head","socket"],["head_size",entry[0]], ["head_height", diam]],drive_size) :
starts_with(head,"pan") ? let (
metric_pan = [ // pan head for phillips or slotted
// diam, slotted diam, phillips diam, phillips depth, ph width, slot width,slot depth
@ -648,11 +643,11 @@ function _screw_info_metric(diam, pitch, head, thread, drive) =
drive_size = drive=="phillips" ? [["drive_size", entry[3]], ["drive_diameter", entry[4]], ["drive_depth",entry[5]], ["drive_width",entry[6]]] :
drive=="slot" ? [["drive_width", entry[7]], ["drive_depth", entry[8]]] : []
)
concat([["head",type], ["head_size", entry[0]], ["head_height", entry[htind]]], drive_size) :
concat([["head",type], ["head_size", entry[0]], ["head_height", entry[htind]]], drive_size) :
head=="button" || head=="cheese" ? let(
metric_button = [ // button, hex drive
// head diam, height, hex, phillips, hex drive depth
[1.6, [2.9, 0.8, 0.9, undef, 0.55]], // These four cases,
[1.6, [2.9, 0.8, 0.9, undef, 0.55]], // These four cases,
[2, [3.5, 1.3, 1.3, undef, 0.69]], // extrapolated hex depth
[2.2, [3.8, 0.9, 1.3, undef, 0.76]], //
[2.5, [4.6, 1.5, 1.5, undef, 0.87]], //
@ -686,19 +681,19 @@ function _screw_info_metric(diam, pitch, head, thread, drive) =
drive_index = drive=="phillips" ? 3 :
drive=="hex" ? 2 : undef,
drive_dim = head=="button" && drive=="hex" ? [["drive_depth", entry[4]]] :
head=="button" && drive=="torx" ? [["drive_size", entry[5]],["drive_depth", entry[6]]] :
head=="button" && drive=="torx" ? [["drive_size", entry[5]],["drive_depth", entry[6]]] :
head=="cheese" && drive=="slot" ? [["drive_width", entry[4]], ["drive_depth", entry[5]]] :
head=="cheese" && drive=="phillips" ? [["drive_diameter", entry[6]], ["drive_depth", entry[7]],
["drive_width", entry[6]/4]]: // Fabricated this width value to fill in missing field
[],
drive_size = is_def(drive_index) ? [["drive_size", entry[drive_index]]] : []
)
concat([["head",head],["head_size",entry[0]], ["head_height", entry[1]]],drive_size, drive_dim) :
concat([["head",head],["head_size",entry[0]], ["head_height", entry[1]]],drive_size, drive_dim) :
starts_with(head,"flat") ? let(
small = head == "flat small" || (head=="flat" && (drive!="hex" && drive!="torx")),
metric_flat_large = [ // for hex drive
[2, [4, 1.3,undef]],
[2.5,[5, 1.5, undef]],
[2.5,[5, 1.5, undef]],
[3, [6, 2 , 1.1, 10, 0.96]],
[4, [8, 2.5, 1.5, 20, 1.34]],
[5, [10, 3 , 1.9, 25, 1.54]],
@ -751,6 +746,7 @@ function _screw_info_metric(diam, pitch, head, thread, drive) =
head_data
);
// Module: screw_head()
// Usage:
// screw_head(screw_info, [details])
@ -758,7 +754,7 @@ function _screw_info_metric(diam, pitch, head, thread, drive) =
// Draws the screw head described by the data structure `screw_info`, which
// should have the fields produced by `screw_info()`. See that function for
// details on the fields. Standard orientation is with the head centered at (0,0)
// and oriented in the +z direction. Flat heads appear below the xy plane.
// and oriented in the +z direction. Flat heads appear below the xy plane.
// Other heads appear sitting on the xy plane.
module screw_head(screw_info,details=false) {
head = struct_val(screw_info, "head");
@ -776,12 +772,12 @@ module screw_head(screw_info,details=false) {
if (in_list(head,["round","pan round","button","fillister","cheese"])) {
base = head=="fillister" ? 0.75*head_height :
head=="pan round" ? .6 * head_height :
head=="cheese" ? .7 * head_height :
head=="cheese" ? .7 * head_height :
0.1 * head_height; // round and button
head_size2 = head=="cheese" ? head_size-2*tan(5)*head_height : head_size; // 5 deg slope on cheese head
cyl(l=base, d1=head_size, d2=head_size2,anchor=BOTTOM, $fn=32)
cyl(l=base, d1=head_size, d2=head_size2,anchor=BOTTOM, $fn=32)
attach(TOP)
rotate_extrude($fn=32)
rotate_extrude($fn=32)
intersection(){
arc(points=[[-head_size2/2,0], [0,-base+head_height * (head=="button"?4/3:1)], [head_size2/2,0]]);
square([head_size2, head_height-base]);
@ -797,16 +793,17 @@ module screw_head(screw_info,details=false) {
if (details)
down(.01)cyl(l=head_height+.02,d=2*head_size/sqrt(3), chamfer=head_size*(1/sqrt(3)-1/2), anchor=BOTTOM);
}
}
}
// Module: screw()
// Usage:
// screw([name],[head],[thread],[drive],[drive_size], [length], [shank], [oversize], [tolerance], [spec], [details], [anchor], [anchor_head], [orient], [spin])
// Description:
// Create a screw.
//
// .
// Most of these parameters are described in the entry for `screw_info()`.
//
// .
// The tolerance determines the actual thread sizing based on the
// nominal size. For UTS threads it is either "1A", "2A" or "3A", in
// order of increasing tightness. The default tolerance is "2A", which
@ -817,8 +814,8 @@ module screw_head(screw_info,details=false) {
// range (variability) of the thread heights. It must be a value from
// 3-9 for crest diameter and one of 4, 6, or 8 for pitch diameter. A
// tolerance "6g" specifies both pitch and crest diameter to be the same,
// but they can be different, with a tolerance like "5g6g" specifies a pitch diameter tolerance of "5g" and a crest diameter tolerance of "6g".
// Smaller numbers give a tighter tolerance. The default ISO tolerance is "6g".
// but they can be different, with a tolerance like "5g6g" specifies a pitch diameter tolerance of "5g" and a crest diameter tolerance of "6g".
// Smaller numbers give a tighter tolerance. The default ISO tolerance is "6g".
// Arguments:
// name = screw specification, e.g. "M5x1" or "#8-32"
// head = head type (see list above). Default: none
@ -826,18 +823,18 @@ module screw_head(screw_info,details=false) {
// drive = drive type. Default: none
// drive_size = size of drive recess to override computed value
// oversize = amount to increase screw diameter for clearance holes. Default: 0
// spec = screw specification from `screw_info()`. If you specify this you can omit all the preceeding parameters.
// spec = screw specification from `screw_info()`. If you specify this you can omit all the preceeding parameters.
// length = length of screw (in mm)
// shank = length of unthreaded portion of screw (in mm). Default: 0
// details = toggle some details in rendering. Default: false
// tolerance = screw tolerance. Determines actual screw thread geometry based on nominal sizing. Default is "2A" for UTS and "6g" for ISO.
// tolerance = screw tolerance. Determines actual screw thread geometry based on nominal sizing. Default is "2A" for UTS and "6g" for ISO.
// anchor = anchor relative to the shaft of the screw
// anchor_head = anchor relative to the screw head
// Example: Selected UTS (English) screws
// $fn=32;
// xdistribute(spacing=8){
// screw("#6", length=12);
// screw("#6-32", head="button", drive="torx",length=12);
// screw("#6-32", head="button", drive="torx",length=12);
// screw("#6-32,3/4", head="hex");
// screw("#6", thread="fine", head="fillister",length=12, drive="phillips");
// screw("#6", head="flat small",length=12,drive="slot");
@ -868,35 +865,35 @@ module screw_head(screw_info,details=false) {
// screw("1/4", thread=0, length=8, anchor=TOP, head="hex");
// ydistribute(spacing=15){
// screw("1/4", thread=0,length=8, anchor=TOP, head="socket", drive="hex");
// screw("1/4", thread=0,length=8, anchor=TOP, head="socket", drive="torx");
// screw("1/4", thread=0,length=8, anchor=TOP, head="socket", drive="torx");
// screw("1/4", thread=0,length=8, anchor=TOP, head="socket");
// }
// ydistribute(spacing=15){
// screw("1/4", thread=0,length=8, anchor=TOP, head="button", drive="hex");
// screw("1/4", thread=0,length=8, anchor=TOP, head="button", drive="torx");
// screw("1/4", thread=0,length=8, anchor=TOP, head="button", drive="torx");
// screw("1/4", thread=0,length=8, anchor=TOP, head="button");
// }
// ydistribute(spacing=15){
// screw("1/4", thread=0,length=8, anchor=TOP, head="round", drive="slot");
// screw("1/4", thread=0,length=8, anchor=TOP, head="round", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="round", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="round");
// }
// ydistribute(spacing=15){
// screw("1/4", thread=0,length=8, anchor=TOP, head="fillister", drive="slot");
// screw("1/4", thread=0,length=8, anchor=TOP, head="fillister", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="fillister", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="fillister");
// }
// ydistribute(spacing=15){
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat", drive="slot");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat", drive="hex");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat", drive="torx");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat", drive="hex");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat", drive="torx");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat large");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat small");
// }
// ydistribute(spacing=15){
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat undercut", drive="slot");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat undercut", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat undercut", drive="phillips");
// screw("1/4", thread=0,length=8, anchor=TOP, head="flat undercut");
// }
// }
@ -920,23 +917,23 @@ module screw_head(screw_info,details=false) {
// screw("M6x0", length=8, anchor=TOP, head="pan flat");
// }
// ydistribute(spacing=15){
// screw("M6x0", length=8, anchor=TOP, head="button", drive="hex");
// screw("M6x0", length=8, anchor=TOP, head="button", drive="torx");
// screw("M6x0", length=8, anchor=TOP, head="button", drive="hex");
// screw("M6x0", length=8, anchor=TOP, head="button", drive="torx");
// screw("M6x0", length=8, anchor=TOP, head="button");
// }
// ydistribute(spacing=15){
// screw("M6x0", length=8, anchor=TOP, head="cheese", drive="slot");
// screw("M6x0", length=8, anchor=TOP, head="cheese", drive="phillips");
// screw("M6x0", length=8, anchor=TOP, head="cheese", drive="phillips");
// screw("M6x0", length=8, anchor=TOP, head="cheese");
// }
// ydistribute(spacing=15){
// screw("M6x0", length=8, anchor=TOP, head="flat", drive="phillips");
// screw("M6x0", length=8, anchor=TOP, head="flat", drive="slot");
// screw("M6x0", length=8, anchor=TOP, head="flat", drive="hex");
// screw("M6x0", length=8, anchor=TOP, head="flat", drive="torx");
// screw("M6x0", length=8, anchor=TOP, head="flat", drive="hex");
// screw("M6x0", length=8, anchor=TOP, head="flat", drive="torx");
// screw("M6x0", length=8, anchor=TOP, head="flat small");
// screw("M6x0", length=8, anchor=TOP, head="flat large");
// }
// screw("M6x0", length=8, anchor=TOP, head="flat large");
// }
// }
// Example: The three different English (UTS) screw tolerances
// module label(val)
@ -944,8 +941,8 @@ module screw_head(screw_info,details=false) {
// difference(){
// children();
// yflip()linear_extrude(height=.35) text(val,valign="center",halign="center",size=8);
// }
// }
// }
// }
// $fn=64;
// xdistribute(spacing=15){
// label("1") screw("1/4-20,5/8", head="hex",orient=DOWN,anchor_head=TOP,tolerance="1A"); // Loose
@ -960,18 +957,21 @@ module screw_head(screw_info,details=false) {
// children();
// ycopies(n=number, spacing=1.5)right(.25*inch-2)up(8-.35)cyl(d=1, h=1);
// }
// }
// }
// $fn=64;
// xdistribute(spacing=17){
// mark(1) nut("1/4-20", thickness=8, diameter=0.5*inch,tolerance="1B");
// mark(2) nut("1/4-20", thickness=8, diameter=0.5*inch,tolerance="2B");
// mark(3) nut("1/4-20", thickness=8, diameter=0.5*inch,tolerance="3B");
// }
// Example: This example shows the gap between nut and bolt at the loosest tolerance for UTS. This gap is what enables the parts to mesh without binding and is part of the definition for standard metal hardware.
// Example(2D): This example shows the gap between nut and bolt at the loosest tolerance for UTS. This gap is what enables the parts to mesh without binding and is part of the definition for standard metal hardware.
// $slop=0;
// $fn=32;
// inch=25.4;
// color("red") render() back_half() screw("1/4-20,1/4", head="hex",orient=UP,anchor=BOTTOM,tolerance="1A");
// render() back_half() down(inch*1/20*.325+inch/20*3) nut("1/4-20", thickness=8, diameter=0.5*inch,tolerance="1B");
// projection(cut=true)xrot(-90){
// screw("1/4-20,1/4", head="hex",orient=UP,anchor=BOTTOM,tolerance="1A");
// down(inch*1/20*2.58) nut("1/4-20", thickness=8, diameter=0.5*inch,tolerance="1B");
// }
module screw(name, head, thread="coarse", drive, drive_size, oversize=0, spec, length, shank=0, tolerance=undef, details=true, anchor=undef,anchor_head=undef,spin=0, orient=UP)
{
@ -998,7 +998,7 @@ module screw(name, head, thread="coarse", drive, drive_size, oversize=0, spec, l
head_anchor = is_def(anchor_head);
attachable(
d = head_anchor ? head_size[0] : diameter, // This code should be tweaked to pass diameter and length more cleanly
l = head_anchor ? head_size[2] : length,
l = head_anchor ? head_size[2] : length,
orient = orient,
anchor = first_defined([anchor, anchor_head, BOTTOM]),
//offset = head_anchor ? [0,0,head_height/2] : [0,0,-length/2],
@ -1015,21 +1015,21 @@ module screw(name, head, thread="coarse", drive, drive_size, oversize=0, spec, l
}
if (threaded>0)
intersection(){
down(unthreaded)
rod(spec, length=threaded+eps, tolerance=tolerance, $fn=sides, anchor=TOP );
down(unthreaded)
_rod(spec, length=threaded+eps, tolerance=tolerance, $fn=sides, anchor=TOP );
if (details)
up(.01)cyl(d=diameter, l=length+.02+eps, chamfer1 = pitch/2, chamfer2 = headless ? pitch/2 : -pitch/2, anchor=TOP, $fn=sides);
}
}
}
driver(spec);
_driver(spec);
}
children();
}
}
module driver(spec)
module _driver(spec)
{
drive = struct_val(spec,"drive");
echo(drive=drive);
@ -1049,13 +1049,13 @@ module driver(spec)
if (drive=="phillips") phillips_drive(size=str("#",drive_size), shaft=diameter,anchor=BOTTOM);
if (drive=="torx") torx_drive(size=drive_size, l=drive_depth+1, center=false);
if (drive=="hex") linear_extrude(height=drive_depth+1) hexagon(id=drive_size);
if (drive=="slot") cuboid([2*struct_val(spec,"head_size"), drive_width, drive_depth+1],anchor=BOTTOM);
if (drive=="slot") cuboid([2*struct_val(spec,"head_size"), drive_width, drive_depth+1],anchor=BOTTOM);
}
}
}
function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef) =
function _ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef) =
let(
P = pitch,
H = P*sqrt(3)/2,
@ -1085,13 +1085,13 @@ function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef)
T_D1_6 = 0.2 <= P && P <= 0.8 ? 433*P - 190*pow(P,1.22) :
P > .8 ? 230 * pow(P,0.7) : undef,
T_D1 = [ // Crest diameter tolerance for minor diameter of nut thread
T_D1 = [ // Crest diameter tolerance for minor diameter of nut thread
[4, 0.63*T_D1_6],
[5, 0.8*T_D1_6],
[5, 0.8*T_D1_6],
[6, T_D1_6],
[7, 1.25*T_D1_6],
[7, 1.25*T_D1_6],
[8, 1.6*T_D1_6]
],
],
rangepts = [0.99, 1.4, 2.8, 5.6, 11.2, 22.4, 45, 90, 180, 300],
d_ind = floor(lookup(diameter,zip(rangepts,list_range(len(rangepts))))),
@ -1105,7 +1105,7 @@ function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef)
[6, T_d2_6],
[7, 1.25*T_d2_6],
[8, 1.6*T_d2_6],
[9, 2*T_d2_6],
[9, 2*T_d2_6],
],
T_D2 = [ // Tolerance for pitch diameter of nut thread
@ -1119,7 +1119,7 @@ function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef)
internal = is_def(internal) ? internal : tolerance[1] != downcase(tolerance[1]),
internalok = !internal || (
len(tolerance)==2 && str_find("GH",tolerance[1])!=undef && str_find("45678",tolerance[0])!=undef),
tol_str = str(tolerance,tolerance),
tol_str = str(tolerance,tolerance),
externalok = internal || (
(len(tolerance)==2 || len(tolerance)==4)
&& str_find("efgh", tol_str[1])!=undef
@ -1129,16 +1129,16 @@ function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef)
)
assert(internalok,str("Invalid internal thread tolerance, ",tolerance,". Must have form <digit><letter>"))
assert(externalok,str("invalid external thread tolerance, ",tolerance,". Must have form <digit><letter> or <digit><letter><digit><letter>"))
let(
let(
tol_num_pitch = str_num(tol_str[0]),
tol_num_crest = str_num(tol_str[2]),
tol_letter = tol_str[1]
)
assert(tol_letter==tol_str[3],str("Invalid tolerance, ",tolerance,". Cannot mix different letters"))
internal ?
internal ?
let( // Nut case
//a=echo("nut", tol_letter, tol_num_pitch, tol_num_crest),
fdev = struct_val(EI,tol_letter)/1000,
fdev = struct_val(EI,tol_letter)/1000,
Tdval = struct_val(T_D1, tol_num_crest)/1000,
df= echo(T_D1=T_D1),
Td2val = struct_val(T_D2, tol_num_pitch)/1000,
@ -1151,7 +1151,7 @@ function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef)
:
let( // Bolt case
//a=echo("bolt"),
fdev = struct_val(es,tol_letter)/1000,
fdev = struct_val(es,tol_letter)/1000,
Tdval = struct_val(T_d, tol_num_crest)/1000,
Td2val = struct_val(T_d2, tol_num_pitch)/1000,
mintrunc = P/8,
@ -1164,7 +1164,7 @@ function ISO_thread_tolerance(diameter, pitch, internal=false, tolerance=undef)
)
[["pitch",P],["d_major",xdiam], ["d_pitch",pitchdiam], ["d_minor",bot],["basic",[mindiam,pdiam,diameter]]];
function UTS_thread_tolerance(diam, pitch, internal=false, tolerance=undef) =
function _UTS_thread_tolerance(diam, pitch, internal=false, tolerance=undef) =
let(
inch = 25.4,
d = diam/inch, // diameter in inches
@ -1176,7 +1176,7 @@ function UTS_thread_tolerance(diam, pitch, internal=false, tolerance=undef) =
)
assert(tolOK,str("Tolerance was ",tolerance,". Must be one of 1A, 2A, 3A, 1B, 2B, 3B"))
let(
LE = 9*P, // length of engagement. Is this right?
LE = 9*P, // length of engagement. Is this right?
pitchtol_2A = 0.0015*pow(d,1/3) + 0.0015*sqrt(LE) + 0.015*pow(P,2/3),
pitchtol_table = [
["1A", 1.500*pitchtol_2A],
@ -1193,7 +1193,7 @@ function UTS_thread_tolerance(diam, pitch, internal=false, tolerance=undef) =
pitchtol+pitch/4/sqrt(3), // Internal case
minortol = tolerance=="1B" || tolerance=="2B" ?
(
d < 0.25 ? constrain(0.05*pow(P,2/3)+0.03*P/d - 0.002, 0.25*P-0.4*P*P, 0.394*P)
d < 0.25 ? constrain(0.05*pow(P,2/3)+0.03*P/d - 0.002, 0.25*P-0.4*P*P, 0.394*P)
: (P > 0.25 ? 0.15*P : 0.25*P-0.4*P*P)
) :
tolerance=="3B" ? constrain(0.05*pow(P,2/3)+0.03*P/d - 0.002, P<1/13 ? 0.12*P : 0.23*P-1.5*P*P, 0.394*P)
@ -1202,11 +1202,11 @@ function UTS_thread_tolerance(diam, pitch, internal=false, tolerance=undef) =
//g=echo(pta2 = pitchtol_2A),
// ff=echo(minortol=minortol, pitchtol=pitchtol, majortol=majortol),
basic_minordiam = d - 5/4*H,
basic_pitchdiam = d - 3/4*H,
basic_pitchdiam = d - 3/4*H,
majordiam = internal ? [d,d] : // A little confused here, paragraph 8.3.2
[d-allowance-majortol, d-allowance],
//ffda=echo(allowance=allowance, majortol=majortol, "*****************************"),
pitchdiam = internal ? [basic_pitchdiam, basic_pitchdiam + pitchtol]
pitchdiam = internal ? [basic_pitchdiam, basic_pitchdiam + pitchtol]
: [majordiam[1] - 3/4*H-pitchtol, majordiam[1]-3/4*H],
minordiam = internal ? [basic_minordiam, basic_minordiam + minortol]
: [pitchdiam[0] - 3/4*H, basic_minordiam - allowance - H/8] // the -H/8 is for the UNR case, 0 for UN case
@ -1230,26 +1230,26 @@ function _exact_thread_tolerance(d,P) =
// Description:
// Determines actual thread geometry for a given screw with specified tolerance. If tolerance is omitted the default is used. If tolerance
// is "none" or 0 then return the nominal thread geometry.
//
// .
// The return value is a structure with the following fields:
// - pitch: the thread pitch
// - d_major: major diameter range
// - d_pitch: pitch diameter range
// - d_major: major diameter range
// - d_pitch: pitch diameter range
// - d_minor: minor diameter range
// - basic: vector `[minor, pitch, major]` of the nominal or "basic" diameters for the threads
function thread_specification(screw_spec, internal=false, tolerance=undef) =
let( diam = struct_val(screw_spec, "diameter"),
let( diam = struct_val(screw_spec, "diameter"),
pitch = struct_val(screw_spec, "pitch")
,k=
tolerance == 0 || tolerance=="none" ? _exact_thread_tolerance(diam, pitch) :
struct_val(screw_spec,"system") == "ISO" ? ISO_thread_tolerance(diam, pitch, internal, tolerance) :
struct_val(screw_spec,"system") == "UTS" ? UTS_thread_tolerance(diam, pitch, internal, tolerance) :
struct_val(screw_spec,"system") == "ISO" ? _ISO_thread_tolerance(diam, pitch, internal, tolerance) :
struct_val(screw_spec,"system") == "UTS" ? _UTS_thread_tolerance(diam, pitch, internal, tolerance) :
assert(false,"Unknown screw system ",struct_val(screw_spec,"system")),
fff=echo(k))
k;
function thread_profile(thread) =
function _thread_profile(thread) =
let(
pitch = struct_val(thread,"pitch"),
basicrad = struct_val(thread,"basic")/2,
@ -1258,7 +1258,7 @@ function thread_profile(thread) =
meanmajorrad = mean(struct_val(thread,"d_major"))/2,
depth = (meanmajorrad-meanminorrad)/pitch,
crestwidth = (pitch/2 - 2*(meanmajorrad-meanpitchrad)/sqrt(3))/pitch
)
[
[-1/2,-depth],
@ -1267,7 +1267,7 @@ function thread_profile(thread) =
[crestwidth + 2*depth/sqrt(3)-1/2,-depth]
];
function thread_profile_e(thread) =
function _thread_profile_e(thread) =
let(
pitch = struct_val(thread,"pitch"),
basicrad = struct_val(thread,"basic")/2,
@ -1276,7 +1276,7 @@ function thread_profile_e(thread) =
meanmajorrad = mean(struct_val(thread,"d_major"))/2,
depth = (meanmajorrad-meanminorrad)/pitch,
crestwidth = (pitch/2 - 2*(meanmajorrad-meanpitchrad)/sqrt(3))/pitch
)
[
[-1/2,-1], // -1 instead of -depth?
@ -1286,25 +1286,26 @@ function thread_profile_e(thread) =
];
module rod(spec, length, tolerance, orient=UP, spin=0, anchor=CENTER)
module _rod(spec, length, tolerance, orient=UP, spin=0, anchor=CENTER)
{
threadspec = thread_specification(spec, internal=false, tolerance=tolerance);
echo(d_major_mean = mean(struct_val(threadspec, "d_major")));
echo(bolt_profile=thread_profile(threadspec));
echo(bolt_profile=_thread_profile(threadspec));
trapezoidal_threaded_rod( d=mean(struct_val(threadspec, "d_major")),
l=length,
pitch = struct_val(threadspec, "pitch"),
profile = thread_profile(threadspec),left_handed=false,
profile = _thread_profile(threadspec),left_handed=false,
bevel=false, orient=orient, anchor=anchor, spin=spin);
}
// Module: nut()
// Usage: nut([name],[thread],[oversize],[spec], [diameter],[thickness], [tolerance], [details])
// Usage:
// nut([name],[thread],[oversize],[spec],[diameter],[thickness],[tolerance],[details])
// Description:
// The name, thread and oversize parameters are described under `screw_info()`
//
// .
// The tolerance determines the actual thread sizing based on the
// nominal size. For UTS threads it is either "1B", "2B" or "3B", in
// order of increasing tightness. The default tolerance is "2B", which
@ -1313,15 +1314,15 @@ module rod(spec, length, tolerance, orient=UP, spin=0, anchor=CENTER)
// from the nominal size, and must be "G", or "H", where "G" is looser
// he loosest and "H" means no gap. The number specifies the allowed
// range (variability) of the thread heights. Smaller numbers give tigher tolerances. It must be a value from
// 4-8, so an allowed (loose) tolerance is "7G". The default ISO tolerance is "6H".
// 4-8, so an allowed (loose) tolerance is "7G". The default ISO tolerance is "6H".
// Arguments:
// name = screw specification, e.g. "M5x1" or "#8-32"
// thread = thread type or specification. Default: "coarse"
// oversize = amount to increase screw diameter for clearance holes. Default: 0
// spec = screw specification from `screw_info()`. If you specify this you can omit all the preceeding parameters.
// spec = screw specification from `screw_info()`. If you specify this you can omit all the preceeding parameters.
// thickness = thickness of bolt (in mm)
// details = toggle some details in rendering. Default: false
// tolerance = nut tolerance. Determines actual nut thread geometry based on nominal sizing. Default is "2B" for UTS and "6H" for ISO.
// tolerance = nut tolerance. Determines actual nut thread geometry based on nominal sizing. Default is "2B" for UTS and "6H" for ISO.
module nut(name, thread="coarse", oversize=0, spec, diameter, thickness, tolerance=undef, details=true, anchor=BOTTOM,spin=0, orient=UP)
{
spec = is_def(spec) ? spec : screw_info(name, thread=thread, oversize=oversize);
@ -1330,14 +1331,14 @@ module nut(name, thread="coarse", oversize=0, spec, diameter, thickness, toleran
echo(nut_minor_diam = mean(struct_val(threadspec,"d_minor")));
trapezoidal_threaded_nut(
od=diameter, id=mean(struct_val(threadspec, "d_major")), h=thickness,
pitch=struct_val(threadspec, "pitch"),
profile=thread_profile(threadspec),
pitch=struct_val(threadspec, "pitch"),
profile=_thread_profile(threadspec),
bevel=false,anchor=anchor,spin=spin,orient=orient);
}
function _is_positive(x) = is_num(x) && x>0;
function _validate_screw_spec(spec) = let(
f=struct_echo(spec),
systemOK = in_list(struct_val(spec,"system"), ["UTS","ISO"]),
@ -1352,8 +1353,8 @@ function _validate_screw_spec(spec) = let(
driveOK = is_undef(drive) || drive=="none"
|| (
_is_positive(struct_val(spec, "drive_depth")) &&
(
in_list(drive, ["torx","hex"])
(
in_list(drive, ["torx","hex"])
|| (drive=="phillips" && _is_positive(struct_val(spec, "drive_diameter")) &&
_is_positive(struct_val(spec, "drive_width")) &&
_is_positive(struct_val(spec, "drive_width")))

View file

@ -82,6 +82,8 @@ def get_comment_block(lines, prefix, blanks=1):
break
else:
blankcnt = 0
if line.rstrip() == '.':
line = "\n"
out.append(line.rstrip())
return (lines, out)
@ -233,7 +235,9 @@ class ImageProcessing(object):
with open(scriptfile, "w") as f:
f.write(script)
if "Big" in extype:
if "Huge" in extype:
imgsize = (800, 600)
elif "Big" in extype:
imgsize = (640, 480)
elif "Med" in extype or "distribute" in script or "show_anchors" in script:
imgsize = (480, 360)

View file

@ -17,7 +17,7 @@ done
if [[ "$FILES" != "" ]]; then
PREVIEW_LIBS="$FILES"
else
PREVIEW_LIBS="affine arrays attachments beziers bottlecaps common constants coords cubetruss debug distributors edges errors geometry hingesnaps hull involute_gears joiners knurling linear_bearings masks math metric_screws mutators nema_steppers partitions paths phillips_drive polyhedra primitives quaternions queues regions rounding shapes shapes2d skin sliders stacks strings structs threading torx_drive transforms triangulation vectors version vnf walls wiring"
PREVIEW_LIBS="affine arrays attachments beziers bottlecaps common constants coords cubetruss debug distributors edges errors geometry hingesnaps hull involute_gears joiners knurling linear_bearings masks math metric_screws mutators nema_steppers partitions paths phillips_drive polyhedra primitives quaternions queues regions rounding screws shapes shapes2d skin sliders stacks strings structs threading torx_drive transforms triangulation vectors version vnf walls wiring"
fi
dir="$(basename $PWD)"

View file

@ -294,8 +294,8 @@ module test_find_circle_3points() {
test_find_circle_3points();
module test_find_circle_tangents() {
tangs = find_circle_tangents(r=50,cp=[0,0],pt=[50*sqrt(2),0]);
module test_circle_point_tangents() {
tangs = circle_point_tangents(r=50,cp=[0,0],pt=[50*sqrt(2),0]);
assert(approx(subindex(tangs,0), [45,-45]));
expected = [for (ang=subindex(tangs,0)) polar_to_xy(50,ang)];
got = subindex(tangs,1);
@ -304,7 +304,7 @@ module test_find_circle_tangents() {
assert(approx(flatten(got), flatten(expected)));
}
}
test_find_circle_tangents();
test_circle_point_tangents();
module test_tri_calc() {

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,319];
BOSL_VERSION = [2,0,331];
// Section: BOSL Library Version Functions