This is the first time I've seen anyone make this connection in a scientific fashion. Check the research is solid before repeating it.
http://www.newscientist.com/article/dn17922-carrying-a-gun-increases-risk-of-getting-shot-and-killed.html

## Friday, December 14, 2012

## Sunday, October 28, 2012

### Cones

Geekin out the maths, and might actually have a use for this again someday. How to custom-design a piece of a cone, to step a cylinder of one size down to another.

I want to step a cylinder of radius r1 down to a new radius r2 over a distance of d. This is a section "trimmed" off the top edge of a cone, so the trick is to first describe the cone. The height of the full cone (h1), the length of its side (s1), and the radius of the larger disk (r1) form a right triangle. Next describe the smaller cone we're cutting off the tip of the larger. The height of the offcut (h2), the length of its side, and the radius of the smaller disk (r2) also form a right triangle. The angle between the height and the side in each of these triangles must be identical. The tangent of that angle is the ratio of the radius over the height, and it also must be identical between the two triangles, so r1/h1 = r2/h2. r1 and r2 were given, and h1 = h2 + d, so we solve for h2:

r1*h2 = r2*h1

h2 = r2/r1*(h2+d)

h2*(1-r2/r1) = r2/r1*d

h2 = r2/r1*d/(1-r2/r1)

h2 = d*r2/(r1-r2)

To draw a template for this cone on flat paper we need a circular sector. The radius of this sector is the length of the side of the cone, which is just the hypoteneuse of the first triangle we described above: s1 = (r1^2 + h1^2)^(1/2). The angle of the sector - effectively, the proportion of a whole disk we use - we can find from the fact that the outer circumference of the sector (not including the "pie cuts") must be equal to the circumference of the base of the cone, which is the disk with r1 from way back in the problem definition. So portion of the disk to use is the ratio of (2*pi*r1)/(2*pi*s1), or simply r1/s1.

So in my case I want to go from a diameter of 5/8" to 3/8" in the course of 3/8". To make life easier, I'll do everything in 16ths.

r1 = 5

r2 = 3

d = 6

h2 = 6*3/(5-3) = 9

h1 = 15

s1 = (5^2 + 15^2)^(1/2) = 15.81

s2 = (3^2 + 9^2)^(1/2) = 9.49

And I want 5/15.81 = 31.62% or 113.84 degrees.

But OpenOffice Draw is not a CAD program, and it won't let me specify the number of degrees in a sector. *grumble*. So subtracting 90 for the orientation, I get sin(23.84) = 0.40, and draw the sector out til its 1.40 inches long with a radius of 1.

(And confirmed by the "print-it-out-and-build-it method...)

I want to step a cylinder of radius r1 down to a new radius r2 over a distance of d. This is a section "trimmed" off the top edge of a cone, so the trick is to first describe the cone. The height of the full cone (h1), the length of its side (s1), and the radius of the larger disk (r1) form a right triangle. Next describe the smaller cone we're cutting off the tip of the larger. The height of the offcut (h2), the length of its side, and the radius of the smaller disk (r2) also form a right triangle. The angle between the height and the side in each of these triangles must be identical. The tangent of that angle is the ratio of the radius over the height, and it also must be identical between the two triangles, so r1/h1 = r2/h2. r1 and r2 were given, and h1 = h2 + d, so we solve for h2:

r1*h2 = r2*h1

h2 = r2/r1*(h2+d)

h2*(1-r2/r1) = r2/r1*d

h2 = r2/r1*d/(1-r2/r1)

h2 = d*r2/(r1-r2)

To draw a template for this cone on flat paper we need a circular sector. The radius of this sector is the length of the side of the cone, which is just the hypoteneuse of the first triangle we described above: s1 = (r1^2 + h1^2)^(1/2). The angle of the sector - effectively, the proportion of a whole disk we use - we can find from the fact that the outer circumference of the sector (not including the "pie cuts") must be equal to the circumference of the base of the cone, which is the disk with r1 from way back in the problem definition. So portion of the disk to use is the ratio of (2*pi*r1)/(2*pi*s1), or simply r1/s1.

So in my case I want to go from a diameter of 5/8" to 3/8" in the course of 3/8". To make life easier, I'll do everything in 16ths.

r1 = 5

r2 = 3

d = 6

h2 = 6*3/(5-3) = 9

h1 = 15

s1 = (5^2 + 15^2)^(1/2) = 15.81

s2 = (3^2 + 9^2)^(1/2) = 9.49

And I want 5/15.81 = 31.62% or 113.84 degrees.

But OpenOffice Draw is not a CAD program, and it won't let me specify the number of degrees in a sector. *grumble*. So subtracting 90 for the orientation, I get sin(23.84) = 0.40, and draw the sector out til its 1.40 inches long with a radius of 1.

(And confirmed by the "print-it-out-and-build-it method...)

## Sunday, April 8, 2012

### multi-dimensional hash slices in Perl

I've tripped over this enough times that you'd think I'd remember it by now, but I never do. And looking up the answer on google always seems to take me an age. So, in keeping with the title of this blog, I shall squirrel it away here in hopes that I'll remember to look here first next time...

I love slices in perl. They're brilliant. But they really don't quite do what you wish they'd do if you're trying to take a slice in the first dimension of a multi-dimensional hash. So if I've got:

%thing = ( "A" => [ "A0","A1","A2","A3" ],

"B" => ["B0","B1","B2","B3"],

"C" => ["C0","C1","C2","C3"]

);

I can happily slice up the last dimension on a constant "column" of the first:

print join ", ", @{$thing{B}}[1..2], "\n";

I can't do the reverse:

# doesn't work

#print join ", ", @thing{B..C}[1], "\n";

There are a couple of ways around this, some of which only work in certain circumstances:

print join ", ", ( map {$_->[1]} @thing{B..C} ), "\n";

works for output, but you don't have a ref to the original object anymore, so you can't change it. So while:

foreach ( @{$thing{B}}[1..2] ) {

s/B/E/;

}

Does what you'd expect - changes the values in B1 and B2:

foreach ( map {$_->[1]} @thing{B..C} ) {

s/1/4/;

}

...doesn't do the equivalent. Instead you need something like:

foreach ( B..C ) {

$thing{$_}[1] =~ s/1/4/;

}

(All of which seems pretty trivial from those examples, but when you try to do something complicated then being able to do all the referencing in the foreach parameter, and just work with $_ inside makes the code a LOT easier to read...)

I love slices in perl. They're brilliant. But they really don't quite do what you wish they'd do if you're trying to take a slice in the first dimension of a multi-dimensional hash. So if I've got:

%thing = ( "A" => [ "A0","A1","A2","A3" ],

"B" => ["B0","B1","B2","B3"],

"C" => ["C0","C1","C2","C3"]

);

I can happily slice up the last dimension on a constant "column" of the first:

print join ", ", @{$thing{B}}[1..2], "\n";

I can't do the reverse:

# doesn't work

#print join ", ", @thing{B..C}[1], "\n";

There are a couple of ways around this, some of which only work in certain circumstances:

print join ", ", ( map {$_->[1]} @thing{B..C} ), "\n";

works for output, but you don't have a ref to the original object anymore, so you can't change it. So while:

foreach ( @{$thing{B}}[1..2] ) {

s/B/E/;

}

Does what you'd expect - changes the values in B1 and B2:

foreach ( map {$_->[1]} @thing{B..C} ) {

s/1/4/;

}

...doesn't do the equivalent. Instead you need something like:

foreach ( B..C ) {

$thing{$_}[1] =~ s/1/4/;

}

(All of which seems pretty trivial from those examples, but when you try to do something complicated then being able to do all the referencing in the foreach parameter, and just work with $_ inside makes the code a LOT easier to read...)

## Tuesday, January 31, 2012

### Weej

They say only the good die young. Well that's shit, but I wish it were true.

Weej was brilliant, and wicked, and magnificent, and big-hearted, and conniving, and mischievous, and brilliant. And never in his life was he anything as bland and pedestrian as merely "good". Oatmeal is "good". Weej was chipotle-marinated spare ribs with garlic-truffle-oil potato mash, a glass of Shiraz, and a double espresso to follow. And probably one of those horrible smoke-sticks of his too. Weej could fill an empty room with a grin.

I read about other people dealing with death, and many say they find comfort in the idea of a god. I'd never dream of taking away anyone's solace at a time like this even if I could - so I'll hide this self-absorbed rant away on this backwater blog where it won't bother anyone. But I've got to get it out. I want to scream it from a rooftop. How could this make you want to worship a god? I want to _invent_ one, just so I can hunt the fucker down and kick his lily-white arse! If I actually believed one was real I'm not sure I could stop myself from writing "Yeah? Well Fuck You Too!" on the side of a mountain in 40-foot letters made of burning bibles. Keep your fucker of a god; I want my friend back.

Weej was brilliant, and wicked, and magnificent, and big-hearted, and conniving, and mischievous, and brilliant. And never in his life was he anything as bland and pedestrian as merely "good". Oatmeal is "good". Weej was chipotle-marinated spare ribs with garlic-truffle-oil potato mash, a glass of Shiraz, and a double espresso to follow. And probably one of those horrible smoke-sticks of his too. Weej could fill an empty room with a grin.

I read about other people dealing with death, and many say they find comfort in the idea of a god. I'd never dream of taking away anyone's solace at a time like this even if I could - so I'll hide this self-absorbed rant away on this backwater blog where it won't bother anyone. But I've got to get it out. I want to scream it from a rooftop. How could this make you want to worship a god? I want to _invent_ one, just so I can hunt the fucker down and kick his lily-white arse! If I actually believed one was real I'm not sure I could stop myself from writing "Yeah? Well Fuck You Too!" on the side of a mountain in 40-foot letters made of burning bibles. Keep your fucker of a god; I want my friend back.

Subscribe to:
Posts (Atom)