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