-
Notifications
You must be signed in to change notification settings - Fork 1
/
beyblade-arena.jscad
235 lines (219 loc) · 5.63 KB
/
beyblade-arena.jscad
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
//
// Beyblade rink, V2
//
function getParameterDefinitions() {
return [{
name: 'resolution',
type: 'int',
initial: 48,
caption: 'Number of divisions of a circle:'
}, {
name: 'layer_h',
type: 'float',
initial: 1,
caption: 'Layer thickness:'
}, {
name: 'arena_top',
type: 'float',
initial: 60.0,
caption: 'Top length of Beyblade arena borders'
}, {
name: 'arena_w',
type: 'float',
initial: 3,
caption: 'width of the Beyblade arena borders'
}, {
name: 'arena_r',
type: 'float',
initial: 200,
caption: 'outer radius of the Beyblade arena'
}, {
name: 'arena_h',
type: 'float',
initial: 20,
caption: 'height of Beyblade arena playground'
}, {
name: 'arena_slope_r',
type: 'float',
initial: 195.0,
caption: 'arena slope radius'
}, {
name: 'arena_slope_d',
type: 'float',
initial: 8.0,
caption: 'arena slope depth'
}, {
name: 'notch_r',
type: 'float',
initial: 6,
caption: 'notch radius'
}, {
name: 'notch_l',
type: 'float',
initial: 10,
caption: 'notch length'
}, {
name: 'part',
type: 'choice',
values: ['piece', 'connecting_pin'],
captions: ['piece', 'connecting pin'],
initial: 'piece',
caption: 'Part:'
}];
}
function main(params) {
var resolutions = [
[6, 16],
[8, 24],
[12, 32],
[24, 64],
[48, 128],
[96, 256]
];
const fn = params.resolution;
//
// Input parameters
//
var pi = 3.14159;
// A bit wider, giving space to the lens buttons
var arena_r = params.arena_r;
var arena_h = params.arena_h;
var arena_w = params.arena_w;
var arena_top = params.arena_top;
var arena_slope_r = params.arena_slope_r;
var arena_slope_d = params.arena_slope_d;
// Outer diameter of the adapter
var notch_l = params.notch_l;
var notch_r = params.notch_r;
var pin_l = notch_l - 2;
var arena_base = notch_r*2;
const arena_cut = 10;
const steps = (arena_top-arena_base)/params.layer_h;
function base_cut(r, w, h) {
var points;
if (w < 0.001) {
points = [[r+h, 0], [r, h], [r-h, 0]];
} else {
points = [[r+h+w/2, 0], [r+w/2, h], [r-w/2, h], [r-h-w/2, 0]];
}
return polygon_cut(points);
}
function middle_cut(r, w, h) {
points = [
[r+h, 0], [r, h], [r-h, 0],
[r-w/2, -h+w/2], [r+w/2, -h+w/2]
];
return polygon_cut(points);
}
function polygon_cut(points) {
var t = linear_extrude({height:10}, polygon({points: points}));
return union(
mirror([0, 0, 1], t.rotateX(-90)),
t.rotateX(90).rotateZ(90)
);
}
//
// arena desired slope, x in the normalized range [0,1], 0 being the center and 1 being the edge
//
function slope(x) {
return arena_base + arena_slope_d*x + ((arena_top-arena_base-arena_slope_d)/(101-x*100));
//return arena_base + arena_slope_d*i/steps + ((arena_top-arena_base-arena_slope_d)/(steps+1-i));
}
// given seartch range[l, h] and expected y, return the desired x
function inv_slope(l, h, y) {
var mid=(l+h)/2;
if ((h-l) < 0.0001) {
return (h+l)/2;
}
if (slope(mid) < y) {
return inv_slope(mid, h, y);
} else {
return inv_slope(l, mid, y);
}
}
// Main cylinder
let arena_wall =
difference(
cylinder({
h: arena_top,
r: arena_r,
center: [true, true, false],
fn: fn
}),
cylinder({
h: arena_top,
r: (arena_r - arena_w),
center: [true, true, false],
fn: fn
})
);
var arena_qtr1 =
difference(
union(
cylinder({
h: arena_h,
r: arena_r,
center: [true, true, false],
fn: fn
}),
arena_wall
),
translate([0, 0, arena_top],
scale([1, 1, arena_slope_d/arena_slope_r],
sphere({
r: (arena_slope_r),
center:true,
fn: fn
})
)
)
);
function arena_pos(i) {
return (3+i*(arena_base+1));
}
var points = Array(steps+4);
var t, th, th2;
points[0] = [0, arena_base];
var last_x = 0;
var x;
for (i = 1; i <= steps; i++) {
x = inv_slope(last_x/arena_slope_r, 1, arena_base+i/steps*(arena_top-arena_base));
points[i] = [x*arena_slope_r
, arena_base+i*(arena_top-arena_base)/steps];
last_x = x;
}
points[steps+1] = [arena_r, arena_top];
points[steps+2] = [arena_r, 0];
points[steps+3] = [0, 0];
arena_qtr1 = rotate_extrude({fn:fn}, polygon({points: points}));
arena_qtr2 = cylinder({h:arena_top, r1:arena_r - arena_cut, r2:arena_r});
var arena_qtr = intersection(arena_qtr1, arena_qtr2);
for (i = 1; (arena_pos(i) < arena_r - arena_cut - arena_base); i++) {
if ((i & 1) == 0){
t = middle_cut(arena_pos(i), 2, (arena_base-3)/2).translate([0, 0, arena_base/2]);
th = slope(arena_pos(i + 0.5)/arena_slope_r); // height of slope
arena_qtr = difference(arena_qtr, t);
}
}
arena_qtr =
intersection(
arena_qtr,
cube({
center: [false, false, true],
size: [arena_r, arena_r, arena_top*2]
})
);
//
// Render
//
switch (params.part) {
case 'piece':
return arena_qtr;
case 'connecting_pin':
pin_height = (arena_base-3)/2;
return intersection(
translate([100, 0, 0], cube({size:[40, 40, 2*(pin_height-0.6)], center:true})),
scale([1, 1.5, 1], middle_cut(100, 2, pin_height-0.2))
);
}
}