Reoriented default right_triangle() and interior_fillet() to more intuitively work with spin.

This commit is contained in:
Revar Desmera 2020-01-13 19:06:56 -08:00
parent c6fc770008
commit 9d9225f9f3
3 changed files with 36 additions and 25 deletions

View file

@ -346,10 +346,15 @@ module position(from)
// attach(from, to, [overlap]) ... // attach(from, to, [overlap]) ...
// Description: // Description:
// Attaches children to a parent object at an anchor point and orientation. // Attaches children to a parent object at an anchor point and orientation.
// Attached objects will be overlapped into the parent object by a little bit,
// as specified by the default `$overlap` value (0.01 by default), or by the
// overriding `overlap=` argument. This is to prevent OpenSCAD from making
// non-manifold objects. You can also define `$overlap=` as an argument in a
// parent module to set the default for all attachments to it.
// Arguments: // Arguments:
// from = The vector, or name of the parent anchor point to attach to. // from = The vector, or name of the parent anchor point to attach to.
// to = Optional name of the child anchor point. If given, orients the child such that the named anchors align together rotationally. // to = Optional name of the child anchor point. If given, orients the child such that the named anchors align together rotationally.
// overlap = Amount to sink child into the parent. Equivalent to `down(X)` after the attach. // overlap = Amount to sink child into the parent. Equivalent to `down(X)` after the attach. This defaults to the value in `$overlap`, which is `0.01` by default.
// norot = If true, don't rotate children when attaching to the anchor point. Only translate to the anchor point. // norot = If true, don't rotate children when attaching to the anchor point. Only translate to the anchor point.
// Example: // Example:
// spheroid(d=20) { // spheroid(d=20) {

View file

@ -445,12 +445,12 @@ module rounded_prismoid(
// Module: right_triangle() // Module: right_triangle()
// //
// Description:
// Creates a 3D right triangular prism.
//
// Usage: // Usage:
// right_triangle(size, [center]); // right_triangle(size, [center]);
// //
// Description:
// Creates a 3D right triangular prism with the hypotenuse in the X+Y+ quadrant.
//
// Arguments: // Arguments:
// size = [width, thickness, height] // size = [width, thickness, height]
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `ALLNEG` // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `ALLNEG`
@ -458,18 +458,17 @@ module rounded_prismoid(
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
// //
// Example: Centered // Example: Centered
// right_triangle([60, 10, 40], center=true); // right_triangle([60, 40, 10], center=true);
// Example: *Non*-Centered // Example: *Non*-Centered
// right_triangle([60, 10, 40]); // right_triangle([60, 40, 10]);
// Example: Standard Connectors // Example: Standard Connectors
// right_triangle([60, 15, 40]) show_anchors(); // right_triangle([60, 40, 15]) show_anchors();
module right_triangle(size=[1, 1, 1], anchor=ALLNEG, spin=0, orient=UP, center=undef) module right_triangle(size=[1, 1, 1], anchor=ALLNEG, spin=0, orient=UP, center=undef)
{ {
size = scalar_vec3(size); size = scalar_vec3(size);
orient_and_anchor(size, orient, anchor, spin=spin, center=center, noncentered=ALLNEG, chain=true) { orient_and_anchor(size, orient, anchor, spin=spin, center=center, noncentered=ALLNEG, chain=true) {
xrot(90) linear_extrude(height=size.z, convexity=2, center=true) {
linear_extrude(height=size.y, convexity=2, center=true) { polygon([[-size.x/2,-size.y/2], [-size.x/2,size.y/2], [size.x/2,-size.y/2]]);
polygon([[-size.x/2,-size.z/2], [-size.x/2,size.z/2], [size.x/2,-size.z/2]]);
} }
children(); children();
} }
@ -1211,8 +1210,9 @@ module pie_slice(
// r = radius of fillet. // r = radius of fillet.
// 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 directional constants from `constants.scad`. Default: `RIGHT`. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `FRONT+LEFT`
// anchor = Alignment of the fillet. Use the constants from `constants.scad`. Default: `CENTER`. // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
// //
// Example: // Example:
// union() { // union() {
@ -1223,19 +1223,25 @@ module pie_slice(
// //
// Example: // Example:
// interior_fillet(l=40, r=10, spin=180); // interior_fillet(l=40, r=10, spin=180);
module interior_fillet(l=1.0, r=1.0, ang=90, overlap=0.01, anchor=CENTER, spin=0, orient=UP) { //
// Example: Using with Attachments
// cube(50,center=true) {
// position(FRONT+LEFT)
// interior_fillet(l=50, r=10, spin=-90);
// position(BOT+FRONT)
// interior_fillet(l=50, r=10, spin=180, orient=RIGHT);
// }
module interior_fillet(l=1.0, r=1.0, ang=90, overlap=0.01, anchor=FRONT+LEFT, spin=0, orient=UP) {
dy = r/tan(ang/2); dy = r/tan(ang/2);
size = [l,r,r]; steps = ceil(segs(r)*ang/360);
orient_and_anchor(size, orient, anchor, spin=spin, chain=true) { step = ang/steps;
difference() { orient_and_anchor([r,r,l], orient, anchor, spin=spin, chain=true) {
translate([0,-overlap/tan(ang/2),-overlap]) { linear_extrude(height=l, convexity=4, center=true) {
if (ang == 90) { path = concat(
translate([0,r/2,r/2]) cube([l,r,r], center=true); [[0,0]],
} else { [for (i=[0:1:steps]) let(a=270-i*step) r*[cos(a),sin(a)]+[dy,r]]
rotate([90,0,90]) pie_slice(ang=ang, r=dy+overlap, h=l, center=true); );
} translate(-[r,r]/2) polygon(path);
}
translate([0,dy,r]) xcyl(l=l+0.1, r=r);
} }
children(); children();
} }

View file

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