Source

boxer / boxer

Full commit
#!/usr/bin/perl
# Generate SVG files with a specified number of sides and tabs
# to make a self-locking acrylic or wooden laser cut box.
#
# (c) 2012 Trammell Hudson <hudson@osresearch.net>
#
use warnings;
use strict;
use Math::Trig;

my $units = "mm"; # mm = 1, inches = 1000 / 25.4
my $thickness = 3;
my $sides = 9;
my $edge = 30;
my $height = 20;

my $deg2rad = 

# Compute the height of the interior triangle
my $interior_angle = 360.0 / $sides;
my $hx = $edge / 2;
my $hy = $hx / tan(deg2rad($interior_angle/2));


print <<"";
<!-- Created with boxer (http://trmm.net/) -->
<svg xmlns="http://www.w3.org/2000/svg">


#
# Draw the top (and bottom piece)
#
#<g transform="translate($edge $edge)">
print <<"";
<g transform="translate(100 100)">

for my $side (0..$sides-1)
{
	my $angle = (360 / $sides) * $side;

	print <<"";
	<g
		transform="rotate(-$angle) translate(-$hx $hy)"
	><path
		stroke="#ff0000"
		d="M

	print <<"";
		0 0
		$edge 0

	print <<"";
	"/><text>$side</text></g>

}

print <<"";
</g>



print <<"";
</svg>

__END__