Skip to content

Commit 343807c

Browse files
author
TimeWaster
committed
changed parameters, changed license and version bump
1 parent 48320f5 commit 343807c

File tree

5 files changed

+143
-774
lines changed

5 files changed

+143
-774
lines changed

Chamfer.png

-7.28 KB
Loading

Chamfer.scad

Lines changed: 75 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
11
/**
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.
35
*
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
237
*/
248

9+
2510
/**
2611
* chamferCube returns an cube with 45° chamfers on the edges of the
2712
* cube. The chamfers are diectly printable on Fused deposition
2813
* modelling (FDM) printers without support structures.
2914
*
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)
4528
*/
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;
4750
chamferCLength = sqrt(chamferHeight * chamferHeight * 2);
51+
4852
difference() {
4953
cube([sizeX, sizeY, sizeZ]);
5054
for(x = [0 : 3]) {
@@ -74,23 +78,38 @@ module chamferCube(sizeX, sizeY, sizeZ, chamferHeight = 1, chamferX = [1, 1, 1,
7478
* the edges of the cylinder. The chamfers are diectly printable on
7579
* Fused deposition modelling (FDM) printers without support structures.
7680
*
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
9094
*/
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+
94113
module cc() {
95114
if(chamferHeight2 != 0) {
96115
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
127146
* standard quality setting (1.0). Order of usage is:
128147
* Standard (1.0) <- globalCircleQuality <- Quality parameter
129148
*
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
133152
*
134153
* @return The number of segments for the circle
135154
*/
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);
137156

138157
// set global quality to 1.0, can be overridden by user
139158
globalCircleQuality = 1.0;

Demo/Demo.scad

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
/**
2+
* This code is published under a
3+
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0
4+
* licence, please respect it.
5+
*
6+
* Chamfered primitives for OpenSCAD v1.0
7+
*/
8+
19
// this changed from "use" to "include" with v0.3!!!
210
include <Chamfers-for-OpenSCAD/Chamfer.scad>;
311

12+
413
// cube demos
5-
translate([-27.5, -5, 12]) chamferCube(10, 10, 10);
6-
translate([-12.5, -5, 12]) chamferCube(10, 10, 10, 2);
7-
translate([2.5, -5, 12]) chamferCube(10, 10, 10, 1, [1, 0, 0, 0]);
8-
translate([17.5, -5, 12]) chamferCube(10, 10, 10, 1, [0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]);
14+
translate([-27.5, -5, 12]) chamferCube([10, 10, 10]);
15+
translate([-12.5, -5, 12]) chamferCube([10, 10, 10], ch=2);
16+
translate([2.5, -5, 12]) chamferCube([10, 10, 10], chamfers=[[1, 0, 0, 0]]);
17+
translate([17.5, -5, 12]) chamferCube([10, 10, 10], [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]], 3);
918

1019
/**
11-
* With this variable you can GLOBALLY override the standard circle quality of 1.0.
20+
* With this variable you can GLOBALLY override the standard circle quality of 1.0,
21+
* but the quality setting in chamferCylinder still has precedence over this variable.
1222
* This variable will only work when set outside of all blocks.
1323
*/
1424
//globalCircleQuality = 0.1;
@@ -18,14 +28,14 @@ translate([-30, 0, -5]) chamferCylinder(10, 5);
1828
translate([-15, 0, -5]) chamferCylinder(10, 5, 5, 2, 4);
1929
translate([0, 0, -5]) chamferCylinder(10, 5, 5, 3, -1);
2030
translate([15, 0, -5]) chamferCylinder(10, 5, 5, 1, undef, 90);
21-
translate([30, 0, -5]) chamferCylinder(10, 5, 5, -1, angle=240);
31+
translate([30, 0, -5]) chamferCylinder(10, 5, 5, -1, a=240);
2232

2333
// cone demos
24-
translate([-30, 0, -20]) chamferCylinder(10, 5, 2, 1, 0, 0.2);
34+
translate([-30, 0, -20]) chamferCylinder(h=10, r=5, r2=2, ch=1, ch2=0);
2535
translate([-15, 0, -20]) chamferCylinder(10, 5, 2, 3, 1);
2636
translate([0, 0, -20]) chamferCylinder(10, 5, 2, -1);
27-
translate([15, 0, -20]) chamferCylinder(10, 5, 2, 1, angle=90);
28-
translate([30, 0, -20]) chamferCylinder(10, 5, 2, -1, angle=240);
37+
translate([15, 0, -20]) chamferCylinder(10, 5, 2, 1, a=90);
38+
translate([30, 0, -20]) chamferCylinder(10, 5, 2, -1, a=240);
2939

3040
// circleSegments demo
3141
translate([-15, 0, -35]) cylinder(h=10, r=5, $fn=circleSegments(5, 0.5));
@@ -41,38 +51,39 @@ translate([15, 0, -50]) cylinder(h=10, r=5, $fn=circleSegments(5));
4151
* cube. The chamfers are diectly printable on Fused deposition
4252
* modelling (FDM) printers without support structures.
4353
*
44-
* @param sizeX The size of the cube along the x axis
45-
* @param sizeY The size of the cube along the y axis
46-
* @param sizeZ The size of the cube along the z axis
47-
* @param chamferHeight The "height" of the chamfers as seen from
48-
* one of the dimensional planes (The real
49-
* width is side c in a right angled triangle)
50-
* @param chamferX Which chamfers to render along the x axis
51-
* in clockwise order starting from the zero
52-
* point, as seen from "Left view" (Ctrl + 6)
53-
* @param chamferY Which chamfers to render along the y axis
54-
* in clockwise order starting from the zero
55-
* point, as seen from "Front view" (Ctrl + 8)
56-
* @param chamferZ Which chamfers to render along the z axis
57-
* in clockwise order starting from the zero
58-
* point, as seen from "Bottom view" (Ctrl + 5)
54+
* @param size The size of the cube along the [x, y, z] axis,
55+
* example: [1, 2, 3]
56+
* @param chamfers Which chamfers to render along the [x, y, z] axis,
57+
* example: [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]]
58+
* X axis: 4 values in clockwise order starting from
59+
* the zero point, as seen from "Left view" (Ctrl + 6)
60+
* Y axis: 4 values in clockwise order starting from
61+
* the zero point, as seen from "Front view" (Ctrl + 8)
62+
* Z axis: 4 values in clockwise order starting from
63+
* the zero point, as seen from "Bottom view" (Ctrl + 5)
64+
* @param ch The "height" of the chamfers as seen from
65+
* one of the dimensional planes (The real
66+
* length is side c in a right angled triangle)
5967
*
6068
* ---------------------------------------------------------------------
6169
*
6270
* chamferCylinder returns an cylinder or cone with 45° chamfers on
6371
* the edges of the cylinder. The chamfers are diectly printable on
6472
* Fused deposition modelling (FDM) printers without support structures.
6573
*
66-
* @param height Height of the cylinder
67-
* @param radius Radius of the cylinder (At the bottom)
68-
* @param radius2 Radius of the cylinder (At the top)
69-
* @param chamferHeight The "height" of the chamfers as seen from
70-
* one of the dimensional planes (The real
71-
* width is side c in a right angled triangle)
72-
* @param angle The radius of the visible part of a wedge
73-
* starting from the x axis counter-clockwise
74-
* @param quality A circle quality factor where 1.0 is a fairly
75-
* good quality, range from 0.0 to 2.0
74+
* @param h Height of the cylinder
75+
* @param r Radius of the cylinder (At the bottom)
76+
* @param r2 Radius of the cylinder (At the top)
77+
* @param ch The "height" of the chamfer at radius 1 as
78+
* seen from one of the dimensional planes (The
79+
* real length is side c in a right angled triangle)
80+
* @param ch2 The "height" of the chamfer at radius 2 as
81+
* seen from one of the dimensional planes (The
82+
* real length is side c in a right angled triangle)
83+
* @param a The angle of the visible part of a wedge
84+
* starting from the x axis counter-clockwise
85+
* @param q A circle quality factor where 1.0 is a fairly
86+
* good quality, range from 0.0 to 2.0-
7687
*
7788
* ---------------------------------------------------------------------
7889
*
@@ -82,10 +93,11 @@ translate([15, 0, -50]) cylinder(h=10, r=5, $fn=circleSegments(5));
8293
* standard quality setting (1.0). Order of usage is:
8394
* Standard (1.0) <- globalCircleQuality <- Quality parameter
8495
*
85-
* @param r Radius of the circle
86-
* @param quality A quality factor, where 1.0 is a fairly good
87-
* quality, range from 0.0 to 2.0
96+
* @param r Radius of the circle
97+
* @param q A quality factor, where 1.0 is a fairly good
98+
* quality, range from 0.0 to 2.0
8899
*
89100
* @return The number of segments for the circle
101+
*
90102
*/
91103

0 commit comments

Comments
 (0)