poly_cylinder() now has a twist parameter.

This commit is contained in:
Chris Palmer 2020-12-18 09:22:39 +00:00
parent fa658d9eaa
commit 73d814d2fe
4 changed files with 96 additions and 17 deletions

View File

@ -6116,6 +6116,16 @@ it gets the linear dimensions right. See <https://hydraraptor.blogspot.com/2011/
The module provides `poly_circle()`, `poly_cylinder()` and `poly_ring()` that is useful for making printed washers and pillars.
`poly_cylinder()` has a `twist` parameter which can be set to make the polygon rotate each layer.
This can be used to mitigate the number of sides being small and make small holes stronger and more round, but is quite slow due to the
large increase in the number of facets.
When set to 1 the polygons alternate each layer, when set higher the rotation takes `twist + 1` layers to repeat.
A small additional rotation is added to make the polygon rotate one more side over the length of the hole to make it appear round when
veiwed end on.
When `twist` is set the resulting cylinder is extended by `eps` at each end so that the exact length of the hole can be used without
leaving a scar on either surface.
[utils/core/polyholes.scad](utils/core/polyholes.scad) Implementation.
@ -6133,7 +6143,7 @@ The module provides `poly_circle()`, `poly_cylinder()` and `poly_ring()` that is
|:--- |:--- |
| ```drill(r, h = 100, center = true)``` | Make a cylinder for drilling holes suitable for CNC routing, set h = 0 for circle |
| ```poly_circle(r, sides = 0)``` | Make a circle adjusted to print the correct size |
| ```poly_cylinder(r, h, center = false, sides = 0, chamfer = false)``` | Make a cylinder adjusted to print the correct size |
| ```poly_cylinder(r, h, center = false, sides = 0, chamfer = false, twist = 0)``` | Make a cylinder adjusted to print the correct size |
| ```poly_drill(r, h = 100, center = true)``` | Make a cylinder for drilling holes suitable for CNC routing if cnc_bit_r is non zero, otherwise a poly_cylinder. |
| ```poly_ring(or, ir, sides = 0)``` | Make a 2D ring adjusted to have the correct internal radius |
| ```poly_tube(or, ir, h, center = false)``` | Make a tube adjusted to have the correct internal radius |
@ -6167,6 +6177,11 @@ The module provides `poly_circle()`, `poly_cylinder()` and `poly_ring()` that is
| 1 | ```rod(9.5, 43)``` | Smooth rod 9.5mm x 43mm |
| 1 | ```rod(9, 41)``` | Smooth rod 9mm x 41mm |
### Printed
| Qty | Filename |
| ---:|:--- |
| 1 | polyhole.stl |
<a href="#top">Top</a>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 136 KiB

View File

@ -21,7 +21,6 @@ include <../utils/core/core.scad>
use <../vitamins/rod.scad>
include <../vitamins/sheets.scad>
module polyholes() {
module positions()
for(i = [1 : 10]) {
translate([(i * i + i) / 2 + 3 * i , 8])
@ -34,17 +33,48 @@ module polyholes() {
children();
}
stl_colour(pp1_colour) linear_extrude(3, center = true)
module polyhole_stl() {
stl("polyhole");
linear_extrude(3, center = true)
difference() {
square([100, 27]);
positions()
poly_circle(r = $r);
}
}
module alt_polyhole_stl() {
holes = [2.5, 2, 1.5];
n = len(holes);
size = [n * 10, 10, 10];
difference() {
translate([-size.x / n / 2, $preview ? 0 : -size.y / 2])
cube($preview ? [size.x, size.y / 2, size.z] : size);
for(i = [0 : n - 1])
translate([i * 10, 0])
if(i % 2)
translate_z(size.z)
poly_cylinder(r = holes[i] / 2, h = 2 * size.z, center = true, twist = i + 1);
else
poly_cylinder(r = holes[i] / 2, h = size.z, center = false, twist = i + 1);
}
}
module polyholes() {
stl_colour(pp1_colour)
polyhole_stl();
positions()
rod(d = 2 * $r, l = 8 * $r + 5);
//
// Alternating polyholes
//
translate([30, -40])
alt_polyhole_stl();
//
// Poly rings
//
ir = 3 / 2;
@ -74,4 +104,11 @@ module polyholes() {
}
}
if($preview)
polyholes();
else {
polyhole_stl();
translate([50, -20])
alt_polyhole_stl();
}

View File

@ -22,6 +22,16 @@
//! it gets the linear dimensions right. See <https://hydraraptor.blogspot.com/2011/02/polyholes.html>
//!
//! The module provides `poly_circle()`, `poly_cylinder()` and `poly_ring()` that is useful for making printed washers and pillars.
//!
//! `poly_cylinder()` has a `twist` parameter which can be set to make the polygon rotate each layer.
//! This can be used to mitigate the number of sides being small and make small holes stronger and more round, but is quite slow due to the
//! large increase in the number of facets.
//! When set to 1 the polygons alternate each layer, when set higher the rotation takes `twist + 1` layers to repeat.
//! A small additional rotation is added to make the polygon rotate one more side over the length of the hole to make it appear round when
//! veiwed end on.
//!
//! When `twist` is set the resulting cylinder is extended by `eps` at each end so that the exact length of the hole can be used without
//! leaving a scar on either surface.
//
function sides(r) = max(round(4 * r), 3); //! Optimium number of sides for specified radius
function corrected_radius(r, n = 0) = r / cos(180 / (n ? n : sides(r))); //! Adjusted radius to make flats lie on the circle
@ -32,7 +42,24 @@ module poly_circle(r, sides = 0) { //! Make a circle adjusted to print the corre
circle(r = corrected_radius(r,n), $fn = n);
}
module poly_cylinder(r, h, center = false, sides = 0, chamfer = false) {//! Make a cylinder adjusted to print the correct size
module poly_cylinder(r, h, center = false, sides = 0, chamfer = false, twist = 0) {//! Make a cylinder adjusted to print the correct size
if(twist) {
slices = ceil(h / layer_height);
twist = min(twist, slices - 1);
sides = sides ? sides : sides(r);
rot = 360 / sides / (twist + 1) * (1 + 1 / slices);
if(center)
for(side = [0, 1])
mirror([0, 0, side])
poly_cylinder(r = r, h = h / 2, sides = sides, twist = twist);
else
render(convexity = 5)
for(i = [0 : slices - 1])
translate_z(i * layer_height - eps)
rotate(rot * i)
poly_cylinder(r = r, h = layer_height + 2 * eps, sides = sides);
}
else
extrude_if(h, center)
poly_circle(r, sides);