+// ---------- cleat ----------
+
+function cleat_frame_theta(s) = s * cleat_horn_tl / cleat_curve_r * 360/TAU;
+function cleat_frame_z(s) = cleat_curve_r * (1 - cos(cleat_frame_theta(s)));
+function cleat_frame_x(s) = cleat_curve_r * sin(cleat_frame_theta(s));
+function cleat_frame_r(s) = ( cleat_horn_d_min * s +
+ cleat_horn_d_max * (1-s) ) * 0.5;
+
+module CleatFrameSphere(r) {
+ scale([1, r[1]/r[0], 1])
+ sphere(r= r[0]);
+}
+
+module CleatFrame(s) {
+ r = cleat_frame_r(s);
+ translate([cleat_frame_x(s), 0, cleat_frame_z(s)])
+ rotate([0, 90, 0])
+ CleatFrameSphere(r);
+}
+
+
+module CleatHorn(){
+ for (si=[0 : cleat_frames-2]) {
+ s0 = si / (cleat_frames-1);
+ s1 = (si+1) / (cleat_frames-1);
+ hull(){
+ CleatFrame(s0);
+ CleatFrame(s1);
+ }
+ }
+}
+
+module CleatBase(){
+ frames = cleat_frames/2;
+ se = cleat_stem_l/2 / cleat_horn_tl;
+ r = cleat_frame_r(se);
+
+ hull(){
+ for (s = [-se, se]) {
+ for (z= [-(cleat_height + tube_dia/2),
+ cleat_frame_z(s)]) {
+ translate([cleat_frame_x(s), 0, z])
+ linear_extrude(height=0.1)
+ scale([1, r[1]/r[0]])
+ circle(r=r[0]);
+ }
+ }
+ }
+}
+
+module VCleat(){
+ intersection(){
+ translate([0,0, vcleat_dz]){
+ difference(){
+ translate([0, -(main_r + cleat_height), 0]) {
+ rotate([0, -90, 90]) {
+ CleatBase();
+ for (m=[0,1]) {
+ mirror([m,0,0]) {
+ CleatHorn();
+ }
+ }
+ }
+ }
+ linextr(-cleat_stem_l, +cleat_stem_l)
+ circle(r = tube_dia/2 + 0.1);
+ }
+ }
+ translate([0,0, total_z * 0.5])
+ cube(center=true,
+ (main_r + cleat_stem_l)*4 * [1,1,0] +
+ total_z * [0,0,2]);
+ }
+}
+
+module VCleatA(){ ////toplevel
+ DummyA();
+ VCleat();
+}
+
+// ---------- hhook ----------
+
+module HHookHookPlan(){
+ translate([0, hhook_ctr]){
+ difference(){
+ circle(r = hhook_outer_dia/2);
+ circle(r = hhook_inside/2);
+ rectfromto([+hhook_outer_dia, -hhook_outer_dia],
+ [0, +hhook_outer_dia]);
+ }
+ translate([0, -(hhook_inside/2 + hhook_th/2)]){
+ hull(){
+ for (x=[-0.1, hhook_l]) {
+ translate([x,0]) square(center=true, hhook_th);
+ }
+ }
+ }
+ }
+}
+
+module HHookA(){ ////toplevel
+ DummyA();
+ linextr(min_z, max_z) {
+ HHookHookPlan();
+ }
+}
+
+module HHookPlanDemo(){
+ MainPlanA();
+ HHookHookPlan();
+}
+
+// ---------- linear bracket ----------
+
+module LinearBracketA(){ ////toplevel
+ difference(){
+ union(){
+ HalfClampXPositive();
+ mirror([1,0,0])
+ linextr_y_xz(-open_gap/2 - linear_bracket_t, -open_gap/2)
+ rectfromto([0, min_z],
+ [max_x + linear_bracket_l, min_z + linear_bracket_h]);
+ }
+ HalfClampXNegative();
+ linextr(-1000,1000)
+ TubePlan();
+ mirror([1,0,0])
+ linextr_y_xz(-100,100) {
+ for (t = [
+ [1,1] * linear_bracket_hole_offset,
+ -[1,1] * linear_bracket_hole_offset +
+ [linear_bracket_l, linear_bracket_h]
+ ]) {
+ translate([ max_x, min_z ] + t)
+ circle(r= linear_bracket_hole_dia/2);
+ }
+ }
+ }
+}
+
+// ---------- misc ----------
+
+module PinSitu(){ ////toplevel
+ difference(){
+ union(){
+ translate([0,0, -pin_head_th])
+ cylinder(r= pin_dia/2, h = total_z + pin_head_th + pin_tail);
+ mirror([0,0,1])
+ cylinder(r= hinge_o_r - pin_gap, h = pin_head_th);
+ }
+ translate([0,0, total_z + pin_tail/2])
+ rotate([0,90,0])
+ translate([0,0, -pin_dia])
+ cylinder(r= pin_hole_dia/2, h=pin_dia*2);
+ translate([pin_dia/2 * cos(45), -50, -pin_head_th*2])
+ cube([50,100, total_z*2]);
+ }
+}
+
+module Pin(){ ////toplevel
+ rotate([0,90,0]) {
+ PinSitu();