Root/cntr/cam/pcb.pl

1#!/usr/bin/perl
2
3$PI = atan2(1, 1)*4;
4
5$d = 25.4/1000*35;
6$r = $d/2-0.1; # compensate deflection of board
7$steps = 24;
8
9
10sub orig
11{
12    $x0 = $_[0];
13    $y0 = $_[1];
14}
15
16
17sub mil
18{
19    return $_[0]/1000*25.4;
20}
21
22
23sub cut
24{
25    if (defined $x) {
26    if ($x == $_[0]+$x0 && $y == $_[1]+$y0) {
27        shift @_;
28        shift @_;
29    } else {
30        print "\n";
31    }
32    }
33    while (@_) {
34    $x = shift @_;
35    $y = shift @_;
36# ($x, $y) = (-$y, $x);
37    $x += $x0;
38    $y += $y0;
39    print "$x $y $z\n";
40    }
41}
42
43
44# 0 is at "noon", rotating counter-clockwise
45
46sub arc
47{
48    local ($xc, $yc, $d, $a0, $a1) = @_;
49    local ($rr) = $d/2;
50    local $n = int(abs($a1-$a0)/360*$steps+0.5);
51
52    $rr = 0 if $rr < 0;
53    for ($i = 0; $i <= $n; $i++) {
54    my $a = ($a0+($a1-$a0)/$n*$i)*$PI/180;
55    $x = $x0+$xc-$rr*sin($a);
56    $y = $y0+$yc+$rr*cos($a);
57    print "$x $y $z\n";
58    }
59}
60
61
62sub circ
63{
64    local ($xc, $yc, $d) = @_;
65
66    print "\n";
67    &arc($xc, $yc, $d, 0, 360);
68    &circ($xc, $yc, $d-$r*2) if $d > $r*2;
69}
70
71
72sub hhole
73{
74    local ($xc0, $xc1, $yc, $d) = @_;
75    local ($rr) = $d/2;
76
77    &cut($xc0, $yc+$rr, $xc1, $yc+$rr);
78    &arc($xc1, $yc, $d, 0, -180);
79    undef $x;
80    &cut($xc1, $yc-$rr, $xc0, $yc-$rr);
81    &arc($xc0, $yc, $d, 180, 0);
82}
83
84
85sub pcb
86{
87    &cut(
88      &mil( 0), &mil( 0),
89      &mil(1080), &mil( 0),
90      &mil(1080), &mil( 620),
91      &mil( 0), &mil( 620),
92      &mil( 0), &mil( 0));
93}
94
95
96sub holes
97{
98    # x-x0, y0-y, diameter
99    &circ(&mil(3130-3020), &mil(3520-3122), &mil(43));
100    &circ(&mil(3130-3020), &mil(3520-3298), &mil(43));
101
102    &hhole(&mil(3100-3020), &mil(3159-3020), &mil(3520-2986), &mil(39));
103    &hhole(&mil(3100-3020), &mil(3159-3020), &mil(3520-3434), &mil(39));
104}
105
106
107
108
109$z = -0.8; # full thickness of board
110# x: corner offset, compensation for rotation, array position
111# y: corner offet
112
113&orig(34*2+3, 3);
114
115$r = $d/2; # no compensation. don't wanna risk making holes too big.
116&holes;
117
118$r = $d/2-0.1; # compensate deflection of board
119&pcb;
120

Archive Download this file



interactive