-
Notifications
You must be signed in to change notification settings - Fork 1
/
othello.jscad
162 lines (155 loc) · 4.61 KB
/
othello.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
//
// Playing piece for Othello (half piece)
//
//include ('jscad-utils.jscad')
//include ('jscad-utils-color.jscad')
function getParameterDefinitions() {
return [{
name: 'resolution',
type: 'choice',
values: [0, 1, 2, 3, 4, 5],
captions: ['very low (6,16)', 'low (8,24)', 'normal (12,32)', 'high (24,64)', 'very high (48,128)',
'ultra high (96,256)'],
initial: 2,
caption: 'Resolution:'
}, {
name: 'part',
type: 'choice',
values: ['piece', 'ring', 'screw', 'flat_piece'],
captions: ['piece (with connecting ring groove)', ' connecting ring', 'screw', 'flat piece (no ring groove)'],
initial: 'piece_flat',
caption: 'Part:'
}];
}
function main(params) {
var resolutions = [
[6, 16],
[8, 24],
[12, 32],
[24, 64],
[48, 128],
[96, 256]
];
CSG.defaultResolution3D = resolutions[params.resolution][0];
CSG.defaultResolution2D = resolutions[params.resolution][1];
//util.init(CSG);
// Radius of part
var base_r = 25/2;
// Height of (half) part
var base_height = 5.1/2;
// Width of the flat ring at the edge
var ring_width = 2.5;
// Max Depth of curve in the middle
var curve_depth=1.8;
// Width of connecting ring
var conn_w = 2 ; // ring_width/3;
// Width of connecting teeth
var teeth_w = 1 ;
// Height of connecting ring
var conn_h = 1;
// extra width for tolerance
var conn_tol = 0.15;
// How many teeths
var num_teeths = 6;
var teeth_angle = 45;
// compensation for plastic warping which we sand later
var height_extra = 0.0;
base_height += height_extra;
if (params.part == 'ring') {
conn_h = (0.75 * conn_h) * 2; // when constructing ring needs to be twice as high to cover both parts
} else {
conn_h += conn_tol;
}
// Solve R^2 = (R-curve_depth)^2+(base_r-ring_width)^2
// This is not a quadratic equation because R^2 cancels on both sides
var r = (Math.pow((base_r-ring_width), 2)+Math.pow(curve_depth, 2))/(2*curve_depth)
var base = CSG.cylinder({
start: [0,0,0],
end: [0, 0, base_height],
radius: base_r
}); //.rotateX(270).chamfer(0.5, 'z+').rotateX(90);
var sphere_cut = CSG.sphere({
center: [0, 0, r+base_height-1.8],
radius: r
});
var ring_outer = CSG.cylinder({
start: [0,0,0],
end: [0, 0, conn_h],
radius: (base_r-conn_w-conn_tol/2)
});
var ring_inner = CSG.cylinder({
start: [0,0,0],
end: [0, 0, conn_h],
radius: (base_r-2*conn_w+conn_tol/2)
});
var ring = ring_outer.subtract(ring_inner);
var flat_piece = base.subtract(sphere_cut);
var piece_ring = flat_piece.subtract(ring);
//
// Screw
//
// cut ring into half-circle and rotate slightly to create screw part,
// then intersect with original ring
var teeth = ring.intersect(ring.subtract(CSG.cube ({
radius: [base_r, base_r, base_r]
}).translate([base_r,0,0])).rotateX(teeth_angle));
// Create "num_teeths" evenly around a circle
var teeths = teeth;
var i;
for (i = 1; i < num_teeths; i++) {
teeths = teeths.union(teeth.rotateZ(i*360/num_teeths));
}
var piece_teeth = flat_piece.union(teeths.translate([0, 0, -conn_h]));
var piece_minus_teeth = flat_piece.subtract(teeths.translate([0, 0, -conn_h]).rotateX(180));
//
// Screw ring
//
var ring_teeth_large = CSG.cylinder({
start: [0,0,-conn_h],
end: [0, 0, conn_h],
radius: (base_r-conn_w+conn_tol/2)
});
var ring_teeth_middle = CSG.cylinder({
start: [0,0,-conn_h],
end: [0, 0, conn_h],
radius: (base_r-2*conn_w+teeth_w+conn_tol/2)
});
var ring_teeth_small = CSG.cylinder({
start: [0,0,-conn_h],
end: [0, 0, conn_h],
radius: (base_r-2*conn_w+conn_tol/2)
});
var ring_for_screw = ring_teeth_large.subtract(ring_teeth_middle);
var ring_for_teeth = ring_teeth_middle.subtract(ring_teeth_small);
var small_teeth =
ring_teeth_middle
.subtract(ring_teeth_small)
.intersect(ring.subtract(CSG.cube ({
radius: [base_r, base_r, base_r]
}).translate([base_r,0,0])).rotateX(teeth_angle));
// Create "num_teeths" evenly around a circle
var small_teeths = ring_for_screw;
var i;
for (i = 0; i < num_teeths; i++) {
small_teeths = small_teeths.union(small_teeth.rotateZ(i*360/num_teeths));
}
var piece_minus_small_teeths = flat_piece.subtract(small_teeths);
//
// Render
//
switch (params.part) {
case 'flat_piece':
return flat_piece;
case 'piece':
return piece_minus_small_teeths;
case 'screw':
return small_teeths;
return union(piece_teeth, piece_minus_teeth.translate([0, 0, 10]));
case 'ring':
var cutout = CSG.cube ({
radius: [2, base_r, conn_h/2]
}).translate([0, base_r/2, conn_h/2]);
ring_cutout = ring.subtract(cutout);
return ring_cutout;
}
}