During one of the corona lockdowns in 2020 I wrote a small Perl script to calculate evenly divided offsets for screws or nails. Later I also used it for irrigation pipe.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
#
my $length = 0;
my $divisions = 0;
my $start = 0;
my $end = 0;
GetOptions(
'length:i' => \$length,
'divisions:i' => \$divisions,
'start:i' => \$start,
'end:i' => \$end
) or die usage();
sub usage{
print <<END;
Calculate equally spaced offset of holes in irrigation pipe
or of screws in piece of wood
\$ \./gap.pl -length 100 -divisions=12 -start=2 -end=4
This will divide (100 - 2 - 4) in 12 equal parts and print the offsets
END
exit(1);
}
&usage if ($length == 0) or ($divisions == 0);
my $increment;
my $position;
my $counter = 0;
$position = $start;
$increment = ($length - $start - $end) / $divisions;
#---
print "\nLength\t\t: $length";
print "\nStart\t\t: $start";
print "\nEnd\t\t: $end";
print "\nDivisions\t: $divisions\n";
print "\nStart\t\t: $start";
print "\nIncrement\t: $increment";
print "\nLast\t\t: \($length - $end)\n";
while ($position < ($length - $end +1)) {
$counter++;
print "\n$counter\t$position";
$position = $position + $increment;
}
print "\n";
Some examples of usage:
Code:
$ ./gap.pl
Calculate equally spaced offset of holes in irrigation pipe
or of screws in piece of wood
$ ./gap.pl -length 100 -divisions=12 -start=2 -end=4
This will divide (100 - 2 - 4) in 12 equal parts and print the offsets
$ ./gap.pl -length 120 -s 6 -end 10 -div 10
Length : 120
Start : 6
End : 10
Divisions : 10
Start : 6
Increment : 10.4
Last : (120 - 10)
1 6
2 16.4
3 26.8
4 37.2
5 47.6
6 58
7 68.4
8 78.8
9 89.2
10 99.6
11 110
$ ./gap.pl -length 120 -s 6 -end 10 -div 15
Length : 120
Start : 6
End : 10
Divisions : 15
Start : 6
Increment : 6.93333333333333
Last : (120 - 10)
1 6
2 12.9333333333333
3 19.8666666666667
4 26.8
5 33.7333333333333
6 40.6666666666667
7 47.6
8 54.5333333333333
9 61.4666666666667
10 68.4
11 75.3333333333334
12 82.2666666666667
13 89.2
14 96.1333333333334
15 103.066666666667
16 110
$
Notice that you can shorten the command line options and that the '=' is optional.
I also don't round the offsets, that is left for the user to decide.
As a metric system user I pity the poor souls that have to figure these things out in inches and feet