chiark / gitweb /
a29c36d79c9aaa7f86f6afb604f9ff3c9c7d311d
[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 Plan(){
56   dy = tubeheight - tuberad*2;
57   FArcSegment(0, dy, tuberad, mainoutrad, -1, 181);
58   FArcSegment(0, 0,  tuberad, mainoutrad, -bend, bend+1);
59   translate([tuberad, 0]) square(center=false, size=[mainthick,dy]);
60   FArcSegment(0, 0, tuberad, tuberad + clipthick, 360-clipang, clipang+1);
61   rotate(-bend) translate([tuberad, 0]) mirror([0,1])
62     square(center=false, size=[mainthick, stemlen/cos(bend)]);
63 }
64
65 module ElevationCore(){
66   FArcSegment(0, hookcy, hookinrad, hookoutrad,
67               180 - ellowextra,
68               90 + hookcurl + ellowextra);
69   translate([-hookoutrad*sqrt(0.5),
70               hookcy - hookoutrad*sqrt(0.5) + 0.1])
71     mirror([1,0])
72     square(center=false, size=[topwidth, stemlen + tubeheight + 20]);
73   polygon([[-hookoutrad, ellow[1]],
74            reflect_in_y(eltop),
75            eltop,
76            elmid,
77            ellow]);
78 }
79
80 // after here is all 3D
81
82 module Primary(){
83   intersection(){
84     translate([0,0, -(topwidth+10)/2])
85       linear_extrude(height=topwidth+10) Plan();
86     translate([50,0])
87       rotate([0,-90,0])
88       linear_extrude(height=100)
89       ElevationCore();
90   }
91 }
92
93 module PlaneAbove(){
94   translate([-100,-100,0]) cube(center=false,size=[200,200,200]);
95 }
96
97 taperangle = -270 + tangent_intersect_beta([-hookcy, 0],
98                                           hookoutrad,
99                                           [-eltop[1], -eltop[0]]);
100 module Hook(){ ////toplevel
101   difference(){
102     rotate([taperangle,0,0])
103       translate([0,-eltop[1],0])
104       Primary();
105     translate([0,0,topwidth/2])
106       rotate([taperangle*2,0,0])
107       PlaneAbove();
108     translate([0,0,-topwidth/2])
109       mirror([0,0,1]) PlaneAbove(0);
110   }
111 }
112
113 //ElevationCore();
114 Hook();