forked from openscad/MCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trochoids.scad
290 lines (259 loc) · 9.17 KB
/
trochoids.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//===========================================
// Public Domain Epi- and Hypo- trochoids in OpenSCAD
// version 1.0
// by Matt Moses, 2011, mmoses152@gmail.com
// http://www.thingiverse.com/thing:8067
//
// This file is public domain. Use it for any purpose, including commercial
// applications. Attribution would be nice, but is not required. There is
// no warranty of any kind, including its correctness, usefulness, or safety.
//
// An EPITROCHOID is a curve traced by a point
// fixed at a distance "d"
// to the center of a circle of radius "r"
// as the circle rolls
// outside another circle of radius "R".
//
// An HYPOTROCHOID is a curve traced by a point
// fixed at a distance "d"
// to the center of a circle of radius "r"
// as the circle rolls
// inside another circle of radius "R".
//
// An EPICYCLOID is an epitrochoid with d = r.
//
// An HYPOCYCLOID is an hypotrochoid with d = r.
//
// See http://en.wikipedia.org/wiki/Epitrochoid
// and http://en.wikipedia.org/wiki/Hypotrochoid
//
// Beware the polar forms of the equations on Wikipedia...
// They are correct, but theta is measured to the center of the small disk!!
//===========================================
// There are several different methods for extruding. The best are probably
// the ones using linear extrude.
//===========================================
// Demo - draws one of each, plus some little wheels and sticks.
//
// Fun stuff to try:
// Animate, try FPS = 5 and Steps = 200
// R = 2, r = 1, d = 0.2
// R = 4, r = 1, d = 1
// R = 2, r = 1, d = 0.5
//
// What happens when you make d > r ??
// What happens when d < 0 ??
// What happens when r < 0 ??
//
//===========================================
$fn = 30;
thickness = 2;
R = 4;
r = 1;
d = 1;
n = 60; // number of wedge segments
alpha = 360*$t;
color([0, 0, 1])
translate([0, 0, -0.5])
cylinder(h = 1, r= R, center = true);
color([0, 1, 0])
epitrochoid(R,r,d,n,thickness);
color([1, 0, 0])
translate([ (R+r)*cos(alpha) , (R+r)*sin(alpha), -0.5]) {
rotate([0, 0, alpha + R/r*alpha]) {
cylinder(h = 1, r = r, center = true);
translate([-d, 0, 1.5]) {
cylinder(h = 2.2, r = 0.1, center = true);
}
}
}
translate([2*(abs(R) + abs(r) + abs(d)), 0, 0]){
color([0, 0, 1])
translate([0, 0, -0.5])
difference() {
cylinder(h = 1, r = 1.1*R, center = true);
cylinder(h = 1.1, r= R, center = true);
}
color([0, 1, 0])
hypotrochoid(R,r,d,n,thickness);
color([1, 0, 0])
translate([ (R-r)*cos(alpha) , (R-r)*sin(alpha), -0.5]) {
rotate([0, 0, alpha - R/r*alpha]) {
cylinder(h = 1, r = r, center = true);
translate([d, 0, 1.5]) {
cylinder(h = 2.2, r = 0.1, center = true);
}
}
}
}
// This just makes a twisted hypotrochoid
translate([0,14, 0])
hypotrochoidLinear(4, 1, 1, 40, 40, 10, 30);
// End of Demo Section
//===========================================
//===========================================
// Epitrochoid
//
module epitrochoid(R, r, d, n, thickness) {
dth = 360/n;
for ( i = [0:n-1] ) {
polyhedron(points = [[0,0,0],
[(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), 0],
[(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), 0],
[0,0,thickness],
[(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), thickness],
[(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), thickness]],
triangles = [[0, 2, 1],
[0, 1, 3],
[3, 1, 4],
[3, 4, 5],
[0, 3, 2],
[2, 3, 5],
[1, 2, 4],
[2, 5, 4]]);
}
}
//===========================================
//===========================================
// Hypotrochoid
//
module hypotrochoid(R, r, d, n, thickness) {
dth = 360/n;
for ( i = [0:n-1] ) {
polyhedron(points = [[0,0,0],
[(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), 0],
[(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), 0],
[0,0,thickness],
[(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), thickness],
[(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), thickness]],
triangles = [[0, 2, 1],
[0, 1, 3],
[3, 1, 4],
[3, 4, 5],
[0, 3, 2],
[2, 3, 5],
[1, 2, 4],
[2, 5, 4]]);
}
}
//===========================================
//===========================================
// Epitrochoid Wedge with Bore
//
module epitrochoidWBore(R, r, d, n, p, thickness, rb) {
dth = 360/n;
union() {
for ( i = [0:p-1] ) {
polyhedron(points = [[rb*cos(dth*i), rb*sin(dth*i),0],
[(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), 0],
[(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), 0],
[rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), 0],
[rb*cos(dth*i), rb*sin(dth*i), thickness],
[(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), thickness],
[(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), thickness],
[rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), thickness]],
triangles = [[0, 1, 4], [4, 1, 5],
[1, 2, 5], [5, 2, 6],
[2, 3, 7], [7, 6, 2],
[3, 0, 4], [4, 7, 3],
[4, 5, 7], [7, 5, 6],
[0, 3, 1], [1, 3, 2]]);
}
}
}
//===========================================
//===========================================
// Epitrochoid Wedge with Bore, Linear Extrude
//
module epitrochoidWBoreLinear(R, r, d, n, p, thickness, rb, twist) {
dth = 360/n;
linear_extrude(height = thickness, convexity = 10, twist = twist) {
union() {
for ( i = [0:p-1] ) {
polygon(points = [[rb*cos(dth*i), rb*sin(dth*i)],
[(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i)],
[(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1))],
[rb*cos(dth*(i+1)), rb*sin(dth*(i+1))]],
paths = [[0, 1, 2, 3]], convexity = 10);
}
}
}
}
//===========================================
//===========================================
// Epitrochoid Wedge, Linear Extrude
//
module epitrochoidLinear(R, r, d, n, p, thickness, twist) {
dth = 360/n;
linear_extrude(height = thickness, convexity = 10, twist = twist) {
union() {
for ( i = [0:p-1] ) {
polygon(points = [[0, 0],
[(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i)],
[(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1))]],
paths = [[0, 1, 2]], convexity = 10);
}
}
}
}
//===========================================
//===========================================
// Hypotrochoid Wedge with Bore
//
module hypotrochoidWBore(R, r, d, n, p, thickness, rb) {
dth = 360/n;
union() {
for ( i = [0:p-1] ) {
polyhedron(points = [[rb*cos(dth*i), rb*sin(dth*i),0],
[(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), 0],
[(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), 0],
[rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), 0],
[rb*cos(dth*i), rb*sin(dth*i), thickness],
[(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), thickness],
[(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), thickness],
[rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), thickness]],
triangles = [[0, 1, 4], [4, 1, 5],
[1, 2, 5], [5, 2, 6],
[2, 3, 7], [7, 6, 2],
[3, 0, 4], [4, 7, 3],
[4, 5, 7], [7, 5, 6],
[0, 3, 1], [1, 3, 2]]);
}
}
}
//===========================================
//===========================================
// Hypotrochoid Wedge with Bore, Linear Extrude
//
module hypotrochoidWBoreLinear(R, r, d, n, p, thickness, rb, twist) {
dth = 360/n;
linear_extrude(height = thickness, convexity = 10, twist = twist) {
union() {
for ( i = [0:p-1] ) {
polygon(points = [[rb*cos(dth*i), rb*sin(dth*i)],
[(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i)],
[(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1))],
[rb*cos(dth*(i+1)), rb*sin(dth*(i+1))]],
paths = [[0, 1, 2, 3]], convexity = 10);
}
}
}
}
//===========================================
//===========================================
// Hypotrochoid Wedge, Linear Extrude
//
module hypotrochoidLinear(R, r, d, n, p, thickness, twist) {
dth = 360/n;
linear_extrude(height = thickness, convexity = 10, twist = twist) {
union() {
for ( i = [0:p-1] ) {
polygon(points = [[0, 0],
[(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i)],
[(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1))]],
paths = [[0, 1, 2]], convexity = 10);
}
}
}
}
//===========================================