|
1 | 1 | /** |
2 | | - * The MIT License (MIT) |
| 2 | + * This code is published under a |
| 3 | + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 |
| 4 | + * licence, please respect it. |
3 | 5 | * |
4 | | - * "Chamfers for OpenSCAD" v0.4 Copyright (c) 2016 SebiTimeWaster |
5 | | - * |
6 | | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | | - * of this software and associated documentation files (the "Software"), to deal |
8 | | - * in the Software without restriction, including without limitation the rights |
9 | | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | | - * copies of the Software, and to permit persons to whom the Software is |
11 | | - * furnished to do so, subject to the following conditions: |
12 | | - * |
13 | | - * The above copyright notice and this permission notice shall be included in all |
14 | | - * copies or substantial portions of the Software. |
15 | | - * |
16 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | | - * SOFTWARE. |
| 6 | + * Chamfered primitives for OpenSCAD v1.0 |
23 | 7 | */ |
24 | 8 |
|
| 9 | + |
25 | 10 | /** |
26 | 11 | * chamferCube returns an cube with 45° chamfers on the edges of the |
27 | 12 | * cube. The chamfers are diectly printable on Fused deposition |
28 | 13 | * modelling (FDM) printers without support structures. |
29 | 14 | * |
30 | | - * @param sizeX The size of the cube along the x axis |
31 | | - * @param sizeY The size of the cube along the y axis |
32 | | - * @param sizeZ The size of the cube along the z axis |
33 | | - * @param chamferHeight The "height" of the chamfers as seen from |
34 | | - * one of the dimensional planes (The real |
35 | | - * width is side c in a right angled triangle) |
36 | | - * @param chamferX Which chamfers to render along the x axis |
37 | | - * in clockwise order starting from the zero |
38 | | - * point, as seen from "Left view" (Ctrl + 6) |
39 | | - * @param chamferY Which chamfers to render along the y axis |
40 | | - * in clockwise order starting from the zero |
41 | | - * point, as seen from "Front view" (Ctrl + 8) |
42 | | - * @param chamferZ Which chamfers to render along the z axis |
43 | | - * in clockwise order starting from the zero |
44 | | - * point, as seen from "Bottom view" (Ctrl + 5) |
| 15 | + * @param size The size of the cube along the [x, y, z] axis, |
| 16 | + * example: [1, 2, 3] |
| 17 | + * @param chamfers Which chamfers to render along the [x, y, z] axis, |
| 18 | + * example: [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]] |
| 19 | + * X axis: 4 values in clockwise order starting from |
| 20 | + * the zero point, as seen from "Left view" (Ctrl + 6) |
| 21 | + * Y axis: 4 values in clockwise order starting from |
| 22 | + * the zero point, as seen from "Front view" (Ctrl + 8) |
| 23 | + * Z axis: 4 values in clockwise order starting from |
| 24 | + * the zero point, as seen from "Bottom view" (Ctrl + 5) |
| 25 | + * @param ch The "height" of the chamfers as seen from |
| 26 | + * one of the dimensional planes (The real |
| 27 | + * length is side c in a right angled triangle) |
45 | 28 | */ |
46 | | -module chamferCube(sizeX, sizeY, sizeZ, chamferHeight = 1, chamferX = [1, 1, 1, 1], chamferY = [1, 1, 1, 1], chamferZ = [1, 1, 1, 1]) { |
| 29 | +module chamferCube(size, chamfers = [undef, undef, undef], ch = 1, ph1 = 1, ph2 = undef, ph3 = undef, ph4 = undef, sizeX = undef, sizeY = undef, sizeZ = undef, chamferHeight = undef, chamferX = undef, chamferY = undef, chamferZ = undef) { |
| 30 | + if(size[0]) { |
| 31 | + chamferCubeImpl(size[0], size[1], size[2], ch, chamfers[0], chamfers[1], chamfers[2]); |
| 32 | + } else { |
| 33 | + // keep backwards compatibility |
| 34 | + size = (sizeX == undef) ? size : sizeX; |
| 35 | + chamfers = (sizeY == undef) ? chamfers : sizeY; |
| 36 | + ch = (sizeZ == undef) ? ch : sizeZ; |
| 37 | + ph1 = (chamferHeight == undef) ? ph1 : chamferHeight; |
| 38 | + ph2 = (chamferX == undef) ? ph2 : chamferX; |
| 39 | + ph3 = (chamferY == undef) ? ph3 : chamferY; |
| 40 | + ph4 = (chamferZ == undef) ? ph4 : chamferZ; |
| 41 | + |
| 42 | + chamferCubeImpl(size, chamfers, ch, ph1, ph2, ph3, ph4); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +module chamferCubeImpl(sizeX, sizeY, sizeZ, chamferHeight, chamferX, chamferY, chamferZ) { |
| 47 | + chamferX = (chamferX == undef) ? [1, 1, 1, 1] : chamferX; |
| 48 | + chamferY = (chamferY == undef) ? [1, 1, 1, 1] : chamferY; |
| 49 | + chamferZ = (chamferZ == undef) ? [1, 1, 1, 1] : chamferZ; |
47 | 50 | chamferCLength = sqrt(chamferHeight * chamferHeight * 2); |
| 51 | + |
48 | 52 | difference() { |
49 | 53 | cube([sizeX, sizeY, sizeZ]); |
50 | 54 | for(x = [0 : 3]) { |
@@ -74,23 +78,38 @@ module chamferCube(sizeX, sizeY, sizeZ, chamferHeight = 1, chamferX = [1, 1, 1, |
74 | 78 | * the edges of the cylinder. The chamfers are diectly printable on |
75 | 79 | * Fused deposition modelling (FDM) printers without support structures. |
76 | 80 | * |
77 | | - * @param height Height of the cylinder |
78 | | - * @param radius Radius of the cylinder (At the bottom) |
79 | | - * @param radius2 Radius of the cylinder (At the top) |
80 | | - * @param chamferHeight The "height" of the chamfer at radius 1 as |
81 | | - * seen from one of the dimensional planes (The |
82 | | - * real width is side c in a right angled triangle) |
83 | | - * @param chamferHeight2 The "height" of the chamfer at radius 2 as |
84 | | - * seen from one of the dimensional planes (The |
85 | | - * real width is side c in a right angled triangle) |
86 | | - * @param angle The radius of the visible part of a wedge |
87 | | - * starting from the x axis counter-clockwise |
88 | | - * @param quality A circle quality factor where 1.0 is a fairly |
89 | | - * good quality, range from 0.0 to 2.0 |
| 81 | + * @param h Height of the cylinder |
| 82 | + * @param r Radius of the cylinder (At the bottom) |
| 83 | + * @param r2 Radius of the cylinder (At the top) |
| 84 | + * @param ch The "height" of the chamfer at radius 1 as |
| 85 | + * seen from one of the dimensional planes (The |
| 86 | + * real length is side c in a right angled triangle) |
| 87 | + * @param ch2 The "height" of the chamfer at radius 2 as |
| 88 | + * seen from one of the dimensional planes (The |
| 89 | + * real length is side c in a right angled triangle) |
| 90 | + * @param a The angle of the visible part of a wedge |
| 91 | + * starting from the x axis counter-clockwise |
| 92 | + * @param q A circle quality factor where 1.0 is a fairly |
| 93 | + * good quality, range from 0.0 to 2.0 |
90 | 94 | */ |
91 | | -module chamferCylinder(height, radius, radius2=undef, chamferHeight = 1, chamferHeight2=undef, angle = 0, quality = -1.0) { |
92 | | - radius2 = (radius2 == undef) ? radius : radius2; |
93 | | - chamferHeight2 = (chamferHeight2 == undef) ? chamferHeight : chamferHeight2; |
| 95 | +module chamferCylinder(h, r, r2 = undef, ch = 1, ch2 = undef, a = 0, q = -1.0, height = undef, radius = undef, radius2 = undef, chamferHeight = undef, chamferHeight2 = undef, angle = undef, quality = undef) { |
| 96 | + // keep backwards compatibility |
| 97 | + h = (height == undef) ? h : height; |
| 98 | + r = (radius == undef) ? r : radius; |
| 99 | + r2 = (radius2 == undef) ? r2 : radius2; |
| 100 | + ch = (chamferHeight == undef) ? ch : chamferHeight; |
| 101 | + ch2 = (chamferHeight2 == undef) ? ch2 : chamferHeight2; |
| 102 | + a = (angle == undef) ? a : angle; |
| 103 | + q = (quality == undef) ? q : quality; |
| 104 | + |
| 105 | + height = h; |
| 106 | + radius = r; |
| 107 | + radius2 = (r2 == undef) ? r : r2; |
| 108 | + chamferHeight = ch; |
| 109 | + chamferHeight2 = (ch2 == undef) ? ch : ch2; |
| 110 | + angle = a; |
| 111 | + quality = q; |
| 112 | + |
94 | 113 | module cc() { |
95 | 114 | if(chamferHeight2 != 0) { |
96 | 115 | translate([0, 0, height - abs(chamferHeight2)]) cylinder(abs(chamferHeight2), r1 = radius2, r2 = radius2 - chamferHeight2, $fn = circleSegments(radius2, quality)); |
@@ -127,13 +146,13 @@ module chamferCylinder(height, radius, radius2=undef, chamferHeight = 1, chamfer |
127 | 146 | * standard quality setting (1.0). Order of usage is: |
128 | 147 | * Standard (1.0) <- globalCircleQuality <- Quality parameter |
129 | 148 | * |
130 | | - * @param r Radius of the circle |
131 | | - * @param quality A quality factor, where 1.0 is a fairly good |
132 | | - * quality, range from 0.0 to 2.0 |
| 149 | + * @param r Radius of the circle |
| 150 | + * @param q A quality factor, where 1.0 is a fairly good |
| 151 | + * quality, range from 0.0 to 2.0 |
133 | 152 | * |
134 | 153 | * @return The number of segments for the circle |
135 | 154 | */ |
136 | | -function circleSegments(r, quality = -1.0) = (r * PI * 4 + 40) * ((quality >= 0.0) ? quality : globalCircleQuality); |
| 155 | +function circleSegments(r, q = -1.0) = (r * PI * 4 + 40) * ((q >= 0.0) ? q : globalCircleQuality); |
137 | 156 |
|
138 | 157 | // set global quality to 1.0, can be overridden by user |
139 | 158 | globalCircleQuality = 1.0; |
0 commit comments