chiark / gitweb /
wardrobe-hook: frontbackly version: wip assing()ish, before revert
[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 mainoutrad = tuberad + mainthick;
46 hookoutrad = hookinrad + hookwidth;
47 $hookcy = -($stemlen - hookoutrad);
48
49 $eltop = [topwidth/2, -tuberad + tubeheight + mainthick + 0.1];
50 $elmid = [topwidth/2, -tuberad];
51 $ellow = tangent_intersect_b([0,$hookcy], hookinrad, $elmid);
52 $ellowextra = 180 - tangent_intersect_beta([0,$hookcy], hookinrad, $elmid);
53
54 $bend = 0;
55
56 module Howly(acrossly_x, frontbackly_x){
57   if (acrossly_x >= 0) {
58     translate([acrossly_x,0,0])
59       assign($bend = atan(tuberad/$stemlen),
60              $frontbackly = 0)
61       child();
62   }
63   if (frontbackly_x >= 0) {
64     translate([frontbackly_x,0,0])
65       assign($bend = 0,
66              $frontbackly = 1)
67       child();
68   }
69 }
70
71 module Plan(){
72   dy = tubeheight - tuberad*2;
73   FArcSegment(0, dy, tuberad, mainoutrad, -1, 181);
74   FArcSegment(0, 0,  tuberad, mainoutrad, -$bend, $bend+1);
75   translate([tuberad, 0]) square(center=false, size=[mainthick,dy]);
76   FArcSegment(0, 0, tuberad, tuberad + clipthick, 360-clipang, clipang+1);
77   rotate(-$bend) translate([tuberad, 0]) mirror([0,1])
78     square(center=false, size=[mainthick, $stemlen/cos($bend)]);
79 }
80
81 module ElevationCore(){
82   FArcSegment(0, $hookcy, hookinrad, hookoutrad,
83               180 - $ellowextra,
84               90 + hookcurl + $ellowextra);
85   translate([-hookoutrad*sqrt(0.5),
86               $hookcy - hookoutrad*sqrt(0.5) + 0.1])
87     mirror([1,0])
88     square(center=false, size=[topwidth, $stemlen + tubeheight + 20]);
89   polygon([[-hookoutrad, $ellow[1]],
90            reflect_in_y($eltop),
91            $eltop,
92            $elmid,
93            $ellow]);
94 }
95
96 // after here is all 3D
97
98 module Primary(){
99   intersection(){
100     translate([0,0, -(topwidth+10)/2])
101       linear_extrude(height=topwidth+10) Plan();
102     translate([50,0])
103       rotate([0,-90,0])
104       linear_extrude(height=100)
105       ElevationCore();
106   }
107 }
108
109 module PlaneAbove(){
110   translate([-100,-100,0]) cube(center=false,size=[200,200,200]);
111 }
112
113 taperangle = -270 + tangent_intersect_beta([-$hookcy, 0],
114                                           hookoutrad,
115                                           [-$eltop[1], -$eltop[0]]);
116 module Hook(){ ////toplevel
117   difference(){
118     rotate([taperangle,0,0])
119       translate([0,-$eltop[1],0])
120       Primary();
121     translate([0,0,topwidth/2])
122       rotate([taperangle*2,0,0])
123       PlaneAbove();
124     translate([0,0,-topwidth/2])
125       mirror([0,0,1]) PlaneAbove(0);
126   }
127 }
128
129 module RightHook(){ ////toplevel
130   mirror([1,0,0]) Hook();
131 }
132
133 module Bothly() {
134   Acrossly() child(0);
135   translate([70,0,0]) Frontbackly() child(0);
136 }
137
138 Howly(0,70) {
139   Plan();
140   //ElevationCore();
141   //RightHook();
142 }