Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save windhooked/c8e170827b6c632e0c1446874470bd35 to your computer and use it in GitHub Desktop.
Save windhooked/c8e170827b6c632e0c1446874470bd35 to your computer and use it in GitHub Desktop.
# Calculate all metric, module and imperial thread pitches
# for a selection of gears.
gears = "20 24 28 30 36 42 44 48 52 56 57 60 66 69 70";
%g = ( 6 => 7 , 5 => 8, 4 => 9, 3 => 10, 2 => 11, 1 => 12 , A => 4, B => 2, C =>1);
$v1 = "1 2 3 4 5 6";
$z1 = "A B C";
#
# 12 11 10 9 8 7
# 1 2 3 4 5 6
#4A
#2B
#1C
# Metric Pitch = DRIVER/DRIVEN 14*P/3*V*Z
# P = x*3*v*z/y*14
sub metric {
my $x = shift;
my $y = shift;
my $v = shift;
my $z = shift;
return (3*$x*$v*$z)/(14*$y);
}
# Module = 44*M/3*V*Z # error in manual
# M = x*3*V*Z/(y*44)
sub module {
my $x = shift;
my $y = shift;
my $v = shift;
my $z = shift;
return ($x*3*$v*$z)/($y*44);
}
# Imperial = 144/V*Z*TPI
# TPI = 144*y/V*Z*x
sub tpi {
my $x = shift;
my $y = shift;
my $v = shift;
my $z = shift;
return (144*$y)/($v*$z*$x);
}
@a = split /\s/, $gears ;
@b = @a;
@v2 = split /\s/, $v1;
@z2 = split /\s/, $z1;
for my $x ( @a ) { # DRIVER
for my $y ( @b ) { #DRIVEN
# print $x . " " . $y . "\n";
for my $v ( @v2 ) { #G JOYSTICK
for my $z ( @z2 ) { #G SELECTOR
print "Metric Pitch, $z, $v, $x, $y, " . metric($x,$y,$g{$v},$g{$z}) ;
print "\n";
print "Module Pitch, $z, $v, $x, $y, " . module($x,$y,$g{$v},$g{$z}) ;
print "\n";
print "Imperial TPI, $z, $v, $x, $y, " . tpi($x,$y,$g{$v},$g{$z}) ;
print "\n";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment