chiark / gitweb /
commitid: Best: Check whether rotated version is better
[reprap-play.git] / wardrobe-hook.scad
1 // -*- C -*-
2
3 include <funcs.scad>
4
5 module FArcSegment_mask(beta) {
6   for (i=[0 : 0.75 : 3]) {
7     rotate(i*beta/4)
8       polygon([[0, 0],
9                [1, 0],
10                [cos(beta/4), sin(beta/4)]]);
11   }
12 }
13
14 module FArcSegment(xc,yc,inrad,outrad,alpha,delta) {
15   translate([xc,yc]) {
16     intersection() {
17       difference() {
18         circle(r=outrad, $fn=70);
19         circle(r=inrad, $fn=70);
20       }
21       rotate(alpha) scale(outrad*2) {
22         FArcSegment_mask(delta);
23       }
24     }
25   }
26 }
27
28 tubeslop = 0.5;
29 tubeheight = 30 + tubeslop;
30 tubewidth = 15 + tubeslop;
31 mainthick = 4;
32
33 clipthick = 2;
34 clipang = 135;
35
36 stemlen = 40;
37
38 topwidth = 20;
39
40 hookinrad = 7.5;
41 hookcurl = 60;
42 hookwidth = 4;
43
44 tuberad = tubewidth/2;
45 bend = atan(tuberad/stemlen);
46 mainoutrad = tuberad + mainthick;
47 hookoutrad = hookinrad + hookwidth;
48 hookcy = -(stemlen - hookoutrad);
49
50 eltop = [topwidth/2, -tuberad + tubeheight + mainthick + 0.1];
51 elmid = [topwidth/2, -tuberad];
52 ellow = tangent_intersect_b([0,hookcy], hookinrad, elmid);
53 ellowextra = 180 - tangent_intersect_beta([0,hookcy], hookinrad, elmid);
54
55 module ClipPlan(qbend, qstemleny){
56   dy = tubeheight - tuberad*2;
57   FArcSegment(0, dy, tuberad, mainoutrad, -1, 181);
58   FArcSegment(0, 0,  tuberad, mainoutrad, -qbend, qbend+1);
59   translate([tuberad, 0]) square(center=false, size=[mainthick,dy]);
60   FArcSegment(0, 0, tuberad, tuberad + clipthick, 360-clipang, clipang+1);
61   rotate(-qbend) translate([tuberad, 0]) mirror([0,1])
62     square(center=false, size=[mainthick, qstemleny/cos(qbend)]);
63 }
64
65 module Plan(){
66   ClipPlan(bend,stemlen);
67 }
68
69 module ElevationCore(){
70   FArcSegment(0, hookcy, hookinrad, hookoutrad,
71               180 - ellowextra,
72               90 + hookcurl + ellowextra);
73   translate([-hookoutrad*sqrt(0.5),
74               hookcy - hookoutrad*sqrt(0.5) + 0.1])
75     mirror([1,0])
76     square(center=false, size=[topwidth, stemlen + tubeheight + 20]);
77   polygon([[-hookoutrad, ellow[1]],
78            reflect_in_y(eltop),
79            eltop,
80            elmid,
81            ellow]);
82 }
83
84 // after here is all 3D
85
86 module Primary(){
87   intersection(){
88     translate([0,0, -(topwidth+10)/2])
89       linear_extrude(height=topwidth+10) Plan();
90     translate([50,0])
91       rotate([0,-90,0])
92       linear_extrude(height=100)
93       ElevationCore();
94   }
95 }
96
97 module PlaneAbove(){
98   translate([-100,-100,0]) cube(center=false,size=[200,200,200]);
99 }
100
101 taperangle = -270 + tangent_intersect_beta([-hookcy, 0],
102                                           hookoutrad,
103                                           [-eltop[1], -eltop[0]]);
104 module HookL(){ ////toplevel
105   difference(){
106     rotate([taperangle,0,0])
107       translate([0,-eltop[1],0])
108       Primary();
109     translate([0,0,topwidth/2])
110       rotate([taperangle*2,0,0])
111       PlaneAbove();
112     translate([0,0,-topwidth/2])
113       mirror([0,0,1]) PlaneAbove(0);
114   }
115 }
116
117 // straight-on version, everything prefixed with s or S
118
119 shookcy = -(stemlen-hookoutrad);
120 sstemleny = -shookcy;
121 sbend_raw = tangents_intersect_beta([0,0],tuberad,
122                                     [0,shookcy],hookinrad);
123 sbend = angle_map_range(360-sbend_raw, -180);
124
125 module SPlan(){
126   ClipPlan(sbend, sstemleny);
127   FArcSegment(0,shookcy, hookinrad,hookoutrad,
128               270 - hookcurl,
129               hookcurl + 90 - sbend);
130 }
131
132 module SElevation(){
133   boty = shookcy - hookoutrad - 1;
134   polygon([[-1,         tubeheight],
135            [topwidth,   tubeheight],
136            [topwidth,   elmid[1]],
137            [hookwidth,  shookcy],
138            [hookwidth,  boty],
139            [-1,         boty]]);
140 }
141
142 module SElevationPlaced(){
143   rotate([0,-90,0]) translate([0,0,-100]) linear_extrude(height=200)
144     SElevation();
145 }
146
147 module SHookL(){ ///toplevel
148   intersection(){
149     linear_extrude(height=topwidth) SPlan();
150     SElevationPlaced();
151   }
152 }
153
154 // straight-on version, reversed, everything prefixed with t or T
155
156 tjoinrad = mainoutrad * 0.7;
157 tstem0leny = tuberad - tjoinrad*0.5;
158 tjoinoutrad = tjoinrad + mainthick;
159
160 thookcy = shookcy;
161
162 tjoin0c = [tuberad - tjoinrad, -tstem0leny];
163 tjoin1c = [0,                      thookcy];
164
165 tbend_raw = tangents_intersect_beta(tjoin0c, tjoinrad,
166                                     tjoin1c, -hookoutrad);
167 tbend0 = angle_map_range(tbend_raw,       0);
168 tbend1 = angle_map_range(tbend_raw + 180, -180);
169
170 tbend0p = circle_point(tjoin0c, tjoinrad, tbend_raw);
171 tbend1p = circle_point(tjoin1c, -hookoutrad, tbend_raw);
172
173 module TPlan(){
174   ClipPlan(0, tstem0leny);
175   FArcSegment(tjoin0c[0],tjoin0c[1], tjoinrad,tjoinoutrad,
176               tbend0, 360-tbend0);
177   FArcSegment(0,shookcy, hookinrad,hookoutrad,
178               tbend1, 270+hookcurl - tbend1);
179   translate(tbend0p) {
180     rotate(tbend_raw+180) mirror([1,0]) {
181       translate([0,-0.1]) square(size=[mainthick, dist2d(tbend0p,tbend1p)+0.2]);
182     }
183   }
184 }
185
186 module THookR(){ ///toplevel
187   intersection(){
188     linear_extrude(height=topwidth) TPlan();
189     SElevationPlaced();
190   }
191 }
192
193 // other toplevels etc.
194
195 module HookR(){ ////toplevel
196   mirror([1,0,0]) HookL();
197 }
198
199 module SHookR(){ ////toplevel
200   mirror([1,0,0]) SHookL();
201 }
202
203 module THookL(){ ////toplevel
204   mirror([1,0,0]) THookR();
205 }
206
207 module Demo(){ ////toplevel
208   translate([-30,tubeheight,0]) HookL();
209   translate([  0,tubeheight,0]) HookR();
210   translate([ 30,         0,0]) SHookL();
211   translate([ 60,         0,0]) SHookR();
212   translate([ 90,         0,0]) THookL();
213   translate([120,         0,0]) THookR();
214 }