chiark / gitweb /
abf2a61292702c9bbd0ccde7eba1ea6f7651cd2d
[reprap-play.git] / pawn.scad
1 // -*- C -*-
2
3 // shape parameters
4
5 r1 =  2.85;
6 r2 =  4; a2 = 27;
7 r3 = r2;
8 r4 =  4; a4 = 18;
9 r5 = 30;
10 h6 = 7; a6 = 4;
11
12 // coordinates
13
14                                 z1 =  0;
15 h2 = r2 * sin(a2);              z2 = z1 - h2;
16 h3 = r3 * sin(a2);              z3 = z2 - h3;
17 h4 = r4 * sin(a4);              z4 = z3 - h4;
18
19 zc5 = z4 - r5 * sin(a4);
20 z5 = zc5 + r5 * sin(a6);        z6 = z5 - h6;
21
22 x1 =  0 - r1;
23 x2 = x1 + r2 * (1-cos(a2));
24 x3 = x2 + r3 * (1-cos(a2));
25 x4 = x3 - r4 * (1-cos(a4));
26
27 xc5 = x4 + r5 * cos(a4);
28 x5 = xc5 - r5 * cos(a6);
29
30 x6 = x5 - h6 * tan(a6);
31
32 htotal = r1 - z6;
33 echo("height", htotal);
34
35 d = 0.01;
36
37 $fa=1;
38 $fs=0.1;
39
40 module SegmentBasisSquare(zmin, zmax, xmin){
41   sqw = -xmin+d;
42   sqh = zmax-zmin+d*2;
43   echo(sqw,sqh);
44   translate([xmin, zmin-d]) square([sqw, sqh]);
45 }
46 module ConvexSegment(xc, zc, r, zmin, zmax){
47   intersection(){
48     translate([xc,zc]) circle(r=r);
49     SegmentBasisSquare(zmin,zmax,-50);
50   }
51 }
52 module ConcaveSegment(xc, zc, r, zmin, zmax){
53   difference(){
54     SegmentBasisSquare(zmin,zmax, xc);
55     translate([xc,zc]) circle(r=r);
56   }
57 }
58
59 module PawnTemplate(){
60   ConvexSegment(  x1 + r1,  z1,   r1, z1, 50);
61   ConvexSegment(  x1 + r2,  z1,   r2, z2, z1);
62   ConcaveSegment( x3 - r3,  z3,   r3, z3, z2);
63   ConcaveSegment( x3 - r4,  z3,   r4, z4, z3);
64   ConvexSegment(  xc5,      zc5,  r5, z5, z4);
65 //  scale([-1,1])
66 //  polygon([[x6, z6],
67 //         [x5, z5+d],
68 //         [d, z5+d],
69 //         [d, z6]]);
70 }
71
72 module Pawn(h=htotal){
73   scale(h/htotal) {
74     rotate_extrude(convexity=10, $fn=50){
75       assign($fn=undef){
76         PawnTemplate();
77       }
78     }
79   }
80 }
81
82 Pawn(h=20);
83 //PawnTemplate();