Skip to content

Commit e79f3cd

Browse files
author
TimeWaster
committed
see changelog in readme
1 parent 3c7f1a9 commit e79f3cd

File tree

6 files changed

+101
-82
lines changed

6 files changed

+101
-82
lines changed

Chamfer.png

-1.11 KB
Loading

Chamfer.scad

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0
44
* licence, please respect it.
55
*
6-
* Chamfered primitives for OpenSCAD v1.0
6+
* Chamfered primitives for OpenSCAD v1.2 - By TimeWaster
77
*/
88

99

@@ -12,11 +12,11 @@
1212
* cube. The chamfers are diectly printable on Fused deposition
1313
* modelling (FDM) printers without support structures.
1414
*
15-
* @param size The size of the cube along the [x, y, z] axis,
15+
* @param size The size of the cube along the [x, y, z] axis,
1616
* example: [1, 2, 3]
17-
* @param chamfers Which chamfers to render along the [x, y, z] axis,
17+
* @param chamfers Which chamfers to render along the [x, y, z] axis,
1818
* example: [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]]
19-
* X axis: 4 values in clockwise order starting from
19+
* X axis: 4 values in clockwise order starting from
2020
* the zero point, as seen from "Left view" (Ctrl + 6)
2121
* Y axis: 4 values in clockwise order starting from
2222
* the zero point, as seen from "Front view" (Ctrl + 8)
@@ -38,11 +38,11 @@ module chamferCube(size, chamfers = [undef, undef, undef], ch = 1, ph1 = 1, ph2
3838
ph2 = (chamferX == undef) ? ph2 : chamferX;
3939
ph3 = (chamferY == undef) ? ph3 : chamferY;
4040
ph4 = (chamferZ == undef) ? ph4 : chamferZ;
41-
41+
4242
chamferCubeImpl(size, chamfers, ch, ph1, ph2, ph3, ph4);
4343
}
4444
}
45-
45+
4646
module chamferCubeImpl(sizeX, sizeY, sizeZ, chamferHeight, chamferX, chamferY, chamferZ) {
4747
chamferX = (chamferX == undef) ? [1, 1, 1, 1] : chamferX;
4848
chamferY = (chamferY == undef) ? [1, 1, 1, 1] : chamferY;
@@ -82,10 +82,10 @@ module chamferCubeImpl(sizeX, sizeY, sizeZ, chamferHeight, chamferX, chamferY, c
8282
* @param r Radius of the cylinder (At the bottom)
8383
* @param r2 Radius of the cylinder (At the top)
8484
* @param ch The "height" of the chamfer at radius 1 as
85-
* seen from one of the dimensional planes (The
85+
* seen from one of the dimensional planes (The
8686
* real length is side c in a right angled triangle)
8787
* @param ch2 The "height" of the chamfer at radius 2 as
88-
* seen from one of the dimensional planes (The
88+
* seen from one of the dimensional planes (The
8989
* real length is side c in a right angled triangle)
9090
* @param a The angle of the visible part of a wedge
9191
* starting from the x axis counter-clockwise
@@ -101,38 +101,39 @@ module chamferCylinder(h, r, r2 = undef, ch = 1, ch2 = undef, a = 0, q = -1.0, h
101101
ch2 = (chamferHeight2 == undef) ? ch2 : chamferHeight2;
102102
a = (angle == undef) ? a : angle;
103103
q = (quality == undef) ? q : quality;
104-
104+
105105
height = h;
106106
radius = r;
107107
radius2 = (r2 == undef) ? r : r2;
108108
chamferHeight = ch;
109109
chamferHeight2 = (ch2 == undef) ? ch : ch2;
110110
angle = a;
111111
quality = q;
112-
112+
113113
module cc() {
114114
upperOverLength = (chamferHeight2 >= 0) ? 0 : 0.01;
115115
lowerOverLength = (chamferHeight >= 0) ? 0 : 0.01;
116+
cSegs = circleSegments(max(radius, radius2), quality);
116117

117118
if(chamferHeight >= 0 || chamferHeight2 >= 0) {
118119
hull() {
119120
if(chamferHeight2 > 0) {
120-
translate([0, 0, height - abs(chamferHeight2)]) cylinder(abs(chamferHeight2), r1 = radius2, r2 = radius2 - chamferHeight2, $fn = circleSegments(radius2, quality));
121+
translate([0, 0, height - abs(chamferHeight2)]) cylinder(abs(chamferHeight2), r1 = radius2, r2 = radius2 - chamferHeight2, $fn = cSegs);
121122
}
122-
translate([0, 0, abs(chamferHeight)]) cylinder(height - abs(chamferHeight2) - abs(chamferHeight), r1 = radius, r2 = radius2, $fn = circleSegments(max(radius, radius2), quality));
123+
translate([0, 0, abs(chamferHeight)]) cylinder(height - abs(chamferHeight2) - abs(chamferHeight), r1 = radius, r2 = radius2, $fn = cSegs);
123124
if(chamferHeight > 0) {
124-
cylinder(abs(chamferHeight), r1 = radius - chamferHeight, r2 = radius, $fn = circleSegments(radius, quality));
125+
cylinder(abs(chamferHeight), r1 = radius - chamferHeight, r2 = radius, $fn = cSegs);
125126
}
126127
}
127128
}
128129

129130
if(chamferHeight < 0 || chamferHeight2 < 0) {
130131
if(chamferHeight2 < 0) {
131-
translate([0, 0, height - abs(chamferHeight2)]) cylinder(abs(chamferHeight2), r1 = radius2, r2 = radius2 - chamferHeight2, $fn = circleSegments(radius2, quality));
132+
translate([0, 0, height - abs(chamferHeight2)]) cylinder(abs(chamferHeight2), r1 = radius2, r2 = radius2 - chamferHeight2, $fn = cSegs);
132133
}
133-
translate([0, 0, abs(chamferHeight) - lowerOverLength]) cylinder(height - abs(chamferHeight2) - abs(chamferHeight) + lowerOverLength + upperOverLength, r1 = radius, r2 = radius2, $fn = circleSegments(max(radius, radius2), quality));
134+
translate([0, 0, abs(chamferHeight) - lowerOverLength]) cylinder(height - abs(chamferHeight2) - abs(chamferHeight) + lowerOverLength + upperOverLength, r1 = radius, r2 = radius2, $fn = cSegs);
134135
if(chamferHeight < 0) {
135-
cylinder(abs(chamferHeight), r1 = radius - chamferHeight, r2 = radius, $fn = circleSegments(radius, quality));
136+
cylinder(abs(chamferHeight), r1 = radius - chamferHeight, r2 = radius, $fn = cSegs);
136137
}
137138
}
138139
}
@@ -169,7 +170,7 @@ module chamferCylinder(h, r, r2 = undef, ch = 1, ch2 = undef, a = 0, q = -1.0, h
169170
*
170171
* @return The number of segments for the circle
171172
*/
172-
function circleSegments(r, q = -1.0) = (r * PI * 4 + 40) * ((q >= 0.0) ? q : globalCircleQuality);
173+
function circleSegments(r, q = -1.0) = (q >= 3 ? q : ((r * PI * 4 + 40) * ((q >= 0.0) ? q : globalCircleQuality)));
173174

174175
// set global quality to 1.0, can be overridden by user
175176
globalCircleQuality = 1.0;

Demo/Artifact-Test.scad

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0
44
* licence, please respect it.
55
*
6-
* Chamfered primitives for OpenSCAD v1.0
6+
* Chamfered primitives for OpenSCAD v1.2 - By TimeWaster
77
*/
88

99
include <Chamfers-for-OpenSCAD/Chamfer.scad>;
1010

1111
/**
1212
* This code is only for testing purposes, please ignore.
13-
*/
13+
*/
1414

1515
difference() {
1616
cube([137, 8, 10]);

Demo/Demo.scad

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,31 @@
33
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0
44
* licence, please respect it.
55
*
6-
* Chamfered primitives for OpenSCAD v1.0
6+
* Chamfered primitives for OpenSCAD v1.2 - By TimeWaster
77
*/
88

99
// this changed from "use" to "include" with v0.3!!!
1010
include <Chamfers-for-OpenSCAD/Chamfer.scad>;
1111

1212

13-
// cube demos
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);
18-
1913
/**
2014
* With this variable you can GLOBALLY override the standard circle quality of 1.0,
2115
* but the quality setting in chamferCylinder still has precedence over this variable.
22-
* This variable will only work when set outside of all blocks.
16+
* This variable will only work when set outside of all blocks and acts globally.
2317
*/
2418
//globalCircleQuality = 0.1;
2519

26-
// cylinder demos
27-
translate([-30, 0, -5]) chamferCylinder(10, 5);
28-
translate([-15, 0, -5]) chamferCylinder(10, 5, 5, 2, 4);
29-
translate([0, 0, -5]) chamferCylinder(10, 5, 5, 3, -1);
30-
translate([15, 0, -5]) chamferCylinder(10, 5, 5, 1, undef, 90);
31-
translate([30, 0, -5]) chamferCylinder(10, 5, 5, -1, a=240);
32-
33-
// cone demos
34-
translate([-30, 0, -20]) chamferCylinder(h=10, r=5, r2=2, ch=1, ch2=0);
35-
translate([-15, 0, -20]) chamferCylinder(10, 5, 2, 3, 1);
36-
translate([0, 0, -20]) chamferCylinder(10, 5, 2, -1);
37-
translate([15, 0, -20]) chamferCylinder(10, 5, 2, 1, a=90);
38-
translate([30, 0, -20]) chamferCylinder(10, 5, 2, -1, a=240);
39-
40-
// circleSegments demo
41-
translate([-15, 0, -35]) cylinder(h=10, r=5, $fn=circleSegments(5, 0.5));
42-
translate([0, 0, -35]) cylinder(h=10, r=5, $fn=circleSegments(5));
43-
translate([15, 0, -35]) cylinder(h=10, r=5, $fn=circleSegments(5, 1.5));
44-
// number of segments depends on circle radius
45-
translate([-15, 0, -50]) cylinder(h=10, r=1, $fn=circleSegments(1));
46-
translate([0, 0, -50]) cylinder(h=10, r=3, $fn=circleSegments(3));
47-
translate([15, 0, -50]) cylinder(h=10, r=5, $fn=circleSegments(5));
4820

4921
/**
5022
* chamferCube returns an cube with 45° chamfers on the edges of the
5123
* cube. The chamfers are diectly printable on Fused deposition
5224
* modelling (FDM) printers without support structures.
5325
*
54-
* @param size The size of the cube along the [x, y, z] axis,
26+
* @param size The size of the cube along the [x, y, z] axis,
5527
* example: [1, 2, 3]
56-
* @param chamfers Which chamfers to render along the [x, y, z] axis,
28+
* @param chamfers Which chamfers to render along the [x, y, z] axis,
5729
* example: [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]]
58-
* X axis: 4 values in clockwise order starting from
30+
* X axis: 4 values in clockwise order starting from
5931
* the zero point, as seen from "Left view" (Ctrl + 6)
6032
* Y axis: 4 values in clockwise order starting from
6133
* the zero point, as seen from "Front view" (Ctrl + 8)
@@ -64,9 +36,14 @@ translate([15, 0, -50]) cylinder(h=10, r=5, $fn=circleSegments(5));
6436
* @param ch The "height" of the chamfers as seen from
6537
* one of the dimensional planes (The real
6638
* length is side c in a right angled triangle)
67-
*
68-
* ---------------------------------------------------------------------
69-
*
39+
*/
40+
translate([-35, -5, 60]) chamferCube([10, 10, 10]);
41+
translate([-20, -5, 60]) chamferCube([10, 10, 10], undef, 2);
42+
translate([-5, -5, 60]) chamferCube([10, 10, 10], [[1, 0, 0, 0]]);
43+
translate([10, -5, 60]) chamferCube([10, 10, 10], [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0]], 3);
44+
45+
46+
/**
7047
* chamferCylinder returns an cylinder or cone with 45° chamfers on
7148
* the edges of the cylinder. The chamfers are diectly printable on
7249
* Fused deposition modelling (FDM) printers without support structures.
@@ -75,18 +52,38 @@ translate([15, 0, -50]) cylinder(h=10, r=5, $fn=circleSegments(5));
7552
* @param r Radius of the cylinder (At the bottom)
7653
* @param r2 Radius of the cylinder (At the top)
7754
* @param ch The "height" of the chamfer at radius 1 as
78-
* seen from one of the dimensional planes (The
55+
* seen from one of the dimensional planes (The
7956
* real length is side c in a right angled triangle)
8057
* @param ch2 The "height" of the chamfer at radius 2 as
81-
* seen from one of the dimensional planes (The
58+
* seen from one of the dimensional planes (The
8259
* real length is side c in a right angled triangle)
8360
* @param a The angle of the visible part of a wedge
8461
* starting from the x axis counter-clockwise
8562
* @param q A circle quality factor where 1.0 is a fairly
86-
* good quality, range from 0.0 to 2.0-
87-
*
88-
* ---------------------------------------------------------------------
89-
*
63+
* good quality, range from 0.0 to 2.0
64+
* If a value of 3.0 or greater is used the quality
65+
* calculation is turned off and the value is directly
66+
* used in $fn
67+
*/
68+
translate([-30, 0, 45]) chamferCylinder(10, 5);
69+
translate([-15, 0, 45]) chamferCylinder(10, 5, 5, 2, 4);
70+
translate([0, 0, 45]) chamferCylinder(10, 5, 5, 3, -1);
71+
translate([15, 0, 45]) chamferCylinder(10, 5, 5, 1, 1, 90);
72+
translate([30, 0, 45]) chamferCylinder(10, 5, 5, -1, -1, 240);
73+
// cones
74+
translate([-30, 0, 30]) chamferCylinder(10, 5, 2, 1, 0);
75+
translate([-15, 0, 30]) chamferCylinder(10, 5, 2, 3, 1);
76+
translate([0, 0, 30]) chamferCylinder(10, 5, 2, -1);
77+
translate([15, 0, 30]) chamferCylinder(10, 5, 2, 1, 1, 90);
78+
translate([30, 0, 30]) chamferCylinder(10, 5, 2, -1, -1, 240);
79+
// simple forms
80+
translate([-30, 0, 15]) chamferCylinder(10, 5, 5, 1, 1, 360, 3);
81+
translate([-15, 0, 15]) chamferCylinder(10, 5, 5, 1, 1, 360, 4);
82+
translate([0, 0, 15]) chamferCylinder(10, 5, 5, 1, 1, 360, 5);
83+
translate([15, 0, 15]) chamferCylinder(10, 5, 5, 1, 1, 360, 6);
84+
translate([30, 0, 15]) chamferCylinder(10, 5, 5, 1, 1, 360, 7);
85+
86+
/**
9087
* circleSegments calculates the number of segments needed to maintain
9188
* a constant circle quality.
9289
* If a globalSegementsQuality variable exist it will overwrite the
@@ -98,6 +95,10 @@ translate([15, 0, -50]) cylinder(h=10, r=5, $fn=circleSegments(5));
9895
* quality, range from 0.0 to 2.0
9996
*
10097
* @return The number of segments for the circle
101-
*
10298
*/
103-
99+
translate([-30, 0, 0]) cylinder(h=10, r=1, $fn=circleSegments(1));
100+
translate([-15, 0, 0]) cylinder(h=10, r=3, $fn=circleSegments(3));
101+
translate([0, 0, 0]) cylinder(h=10, r=5, $fn=circleSegments(5));
102+
translate([15, 0, 0]) cylinder(h=10, r=5, $fn=circleSegments(5, 0.5));
103+
translate([30, 0, 0]) cylinder(h=10, r=5, $fn=circleSegments(5, 1.5));
104+

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Chamfered primitives for OpenSCAD v1.0 - By TimeWaster
1+
Chamfered primitives for OpenSCAD v1.2 - By TimeWaster
22

33
This Project is published under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 licence, please respect it.
44

5-
https://creativecommons.org/licenses/by-nc-sa/3.0/
5+
https://creativecommons.org/licenses/by-nc-sa/3.0/

README.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,70 @@
11
# Chamfered primitives for OpenSCAD
2+
23
A library to create primitives with 45° chamfers in OpenSCAD.
34

45
## What it does
6+
57
The commands `chamferCube` and `chamferCylinder` can be used to create chamfered versions of the existing `cube` and `cylinder` commands.
68

79
The Chamfers are always at a 45° angle to the ground plane and are printable on Fused deposition modelling (FDM) printers in a good quality.
810

911
![Demo of possiblities with chamfers](https://github.com/SebiTimeWaster/OpenSCAD-Chamfer/blob/master/Chamfer.png)
1012

1113
Additionally
12-
* The `chamferCylinder` can also produce a circular sector (wedge), what the cylinder command cannot
13-
* The `circleSegments` function calculates the amount of segments needed for a certain circle radius, it reproduces a much better quality than $fa and $fs settings
14-
* A `globalCircleQuality` variable can be set to globally override the standard setting of 1.0, but the quality setting in `chamferCylinder` stil has precedence over this variable
14+
15+
- The `chamferCylinder` can also produce a circular sector (wedge), what the cylinder command cannot
16+
- The `circleSegments` function calculates the amount of segments needed for a certain circle radius, it reproduces a much better quality than $fa and $fs settings
17+
- A `globalCircleQuality` variable can be set to globally override the standard setting of 1.0, but the quality setting in `chamferCylinder` stil has precedence over this variable
1518

1619
## Installation
20+
1721
First find out where your library folder is by opening OpenSCAD and clicking "File -> Show Library Folder", then do:
1822

19-
* [Download](https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD/releases) the library
20-
* Unpack it to the library folder
21-
* Restart OpenSCAD
23+
- [Download](https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD/releases) the library
24+
- Unpack it to the library folder
25+
- Restart OpenSCAD
2226

2327
OR
2428

25-
* Open your console
26-
* Go to the library folder
27-
* Run ```git clone https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD.git```
28-
* Restart OpenSCAD
29+
- Open your console
30+
- Go to the library folder
31+
- Run `git clone https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD.git`
32+
- Restart OpenSCAD
2933

3034
## Usage
35+
3136
Don't forget to import the library to your script by adding this to the first line:
3237

3338
`include <Chamfers-for-OpenSCAD/Chamfer.scad>;`
3439

3540
Please read the documentation in [Demo.scad](https://github.com/SebiTimeWaster/OpenSCAD-Chamfer/blob/master/Demo/Demo.scad) to see how to use it.
3641

3742
## Changelog
43+
44+
v1.2:
45+
46+
- Added the possibility to create arbitrary sided "cylinders" to create geometic shapes like extruded triangles and so on
47+
- Fixed regression introduced in v1.1 where certain radius combinations result in wrong form generation due to wrong segment calculation
48+
- Improved demo file formatting
49+
3850
v1.1:
39-
* Improved preview rendering of cylinders (see [Artifact-Test.scad](https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD/blob/master/Demo/Artifact-Test.scad))
51+
52+
- Improved preview rendering of cylinders (see [Artifact-Test.scad](https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD/blob/master/Demo/Artifact-Test.scad))
4053

4154
v1.0:
42-
* Changed parameters of `chamferCube` and `chamferCylinder` to work similar to the original `cube` and `cylinder` commands. This is not a breaking change, but please contact me should you encounter compatibility problems.
43-
* Changed license from GPL 3.0 to Creative Commons license to give users more freedom.
55+
56+
- Changed parameters of `chamferCube` and `chamferCylinder` to work similar to the original `cube` and `cylinder` commands. This is not a breaking change, but please contact me should you encounter compatibility problems.
57+
- Changed license from GPL 3.0 to Creative Commons license to give users more freedom.
4458

4559
v0.4:
46-
* Added separate chamfer parameters for the top and bottom sides of cylinders
60+
61+
- Added separate chamfer parameters for the top and bottom sides of cylinders
4762

4863
v0.3:
49-
* Added a global override for the standard circle quality
64+
65+
- Added a global override for the standard circle quality
5066

5167
v0.2:
52-
* Added new circle quality feature (segment calculator) which introduces an incompatibility with v0.1
53-
* Prevented cylinders with height 0 from being created when setting chamferHeight to 0
68+
69+
- Added new circle quality feature (segment calculator) which introduces an incompatibility with v0.1
70+
- Prevented cylinders with height 0 from being created when setting chamferHeight to 0

0 commit comments

Comments
 (0)