Perl script to compute bolt hole pattern
scratch the old version, here's the new one
#!/usr/bin/perl
# If you have a mill with a DRO, and/or a rotary table then you may find
# this script handy when dividing circles. To print the angles (in
# degrees, minutes and seconds) you just specify the number of
# divisions.
#
# If you want to calculate bolt hole pattern given a certain radius
# (assuming that coordinate (0,0) is the center of the circle), you give
# this script an optional argument --radius.
#
# Copyright(C) 2009, Igor Chudov.
# Distributed under the terms of the GNU PUBLIC LICENSE V2
#
use strict;
use warnings;
use Getopt::Long;
my $radius = undef;
my $pi = 3.141592653589793;
GetOptions(
"r|radius=f", \$radius,
);
my $number = shift @ARGV || die "USAGE: $0 number";
$number =~ /^\d+$/ || die "USAGE: $0 number";;
foreach( my $i = 0; $i $number; $i++ ) {
my $angle = 360/$number*$i;
my $degrees = int( $angle );
my $minutes = int( ($angle - $degrees) * 60 );
my $seconds = int( int( ($angle - $degrees - $minutes/60)*60*60 ) );
my $xy = "";
if( $radius ) {
$xy = sprintf( ", x = %.4f, y = %.4f",
$radius * cos( 2*$pi*$angle/360 ),
$radius * sin( 2*$pi*$angle/360 )
);
}
print sprintf( "%d: %03d %02d' %02d\" (%f) %s\n", $i+1, $degrees, $minutes, $seconds, $angle, $xy );
}
|