chiark / gitweb /
wardrobe-hook: frontbackly version: wip new approach
[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 Hook(){ ////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 // frontbackly version, everything prefixed with f or F
118
119 fstemleny = -hookcy;
120 fbend = atan((tuberad - hookinrad) / fstemleny);
121
122 module FPlan(){
123   ClipPlan(fbend, fstemleny);
124 }
125
126 // toplevels etc.
127
128 module RightHook(){ ////toplevel
129   mirror([1,0,0]) Hook();
130 }
131
132 FPlan();
133 translate([60,0,0]) Plan();
134 //ElevationCore();
135 //RightHook();