Sunday, September 7, 2014

A Google Apps Sheet for STV Elections

I've been using Google apps like Sheets in my Kickstarter project, but one thing Sheets doesn't do is complex surveys. While you can link a survey to a sheet, the survey question types are pretty basic, and in particular it does not let you do a ranked survey (in other words, "here are N options, pick any number of them that you like and place them in order of preference.")

When I was on the EVE Online Council of Stellar Management, I became quite the election-systems nerd, because I was pushing hard for a reform of the election system. So just for fun, I decided to see if I could implement a Multiple-Choice Ballot in Google Apps.

What I ended up was a sheet with a bunch of embedded scripts that lets you:

  • Create a Multiple-Choice Ballot with optional additional questions (radios, dropdowns and fields) and voter validation.
  • Store the results in a sheet.
  • Export the results in the standard .blt ballot format used by many election systems.
  • And best of all, run the election using the Simple-STV and Wright-STV systems.
You can find the template sheet at Just make a copy of it in your own Google Drive and start playing with it.


Wednesday, February 5, 2014

Clever Combining CSV Files to Cure KickStarter Conundrums

I recently ran a successful KickStarter for a Bubblegum Crisis Ultimate Edition (you can still sign up here), and in the aftermath ran into an annoying problem.

KickStarter lets you run a Backer Survey after the project is funded, and that's how backers tell you things like their names, addresses and so on. A typical KickStarter will have many different "support levels" providing different benefits.

Annoyingly, KickStarter forces you to design a survey format for each individual support level, with no way of cloning surveys. But what really got me steamed was the discovery that when you export the survey results, you get a CSV file for each survey, and the format of that CSV file depends on the items in each individual survey.

That makes it a royal pain in the ass to import the data into your own database -- I mean, I had 38 CSV files, each with its own ordering of fields. Plus given that people take their time filling out the surveys (2 months later and they're still trickling in), I was going to be doing the import multiple times.

To solve this, I wrote a quick little python script,, that reads in an entire directory of CSV files, extracts all the unique field names from them, and then outputs a single file containing all the rows of data, with a column for each unique field. In cases where a row does not have an entry for a particular field, it gets a blank entry. Also, if a file contains multiple columns that have the same name, the data in them is combined into a single column, separated by the | delimiter.

Added: optional count field name; if present, each unique line is emitted only once, with the last field being a count of the number of occurrences. If not present, the source file name is appended.

You can find it here:

You use it like this:

python [source directory] [destination csv file] {optional count field name}


Update: I also whipped up a standalone AllCSV app that does the same thing; available for both Mac and Windows. It does not currently do the occurrence counting.

Tuesday, September 3, 2013

Voronoi-tesselated Klein Bottle

OK, I admit I've caught the bug of messing around with Math objects and making pretty printable objects from them.

This is my take on the Klein Bottle, inspired in large part by Dizingof's perforated bottle. Mine, however, uses the Voronoi tesselation to perforate the bottle. The various files are available on Thingiverse if you'd like to mess with it.

It was made by using ViaCad and MeshLab, as follows:

* In Viacad, I created 3 surfaces: the bottle body, the neck, and a patch that covers the intersection of the bottle and the neck. The bottle and neck were exported as very fine meshes, the patch as a regular resolution mesh.

* In MeshLab, I imported the bottle and the patch.

* Filters > Color... > Disk Vertex Coloring to color the Bottle using the points in the patch, adjusting the parameter until the patch was fully colored.

* Render > Color > None and then Filters > Selection > Select Faces by Color. Select RGB mode, set the sliders all to 1, turn on Preview, and then tune down the R value until you get everything selected but the patch area.

* Filters > Selection > Invert Selection, then Filters > Selection > Delete Selected Faces and Vertices to make the hole. It will be a bit bigger than the patch, but this is what you want, it makes for a nice effect.

* This is a good point to save your work. MeshLab gets crashy if you do too much, so make a lot of checkpoints. As a general rule, if something is crashing MeshLab -- or not giving proper results -- get things to the point just before the crash, save, then restart MeshLab and import the saved mesh.

* Turn off display of the patch, then Import the Neck. If the neck has a different shade from the bottle, then Filters > Normals > Invert Faces... to change the normals.

* Filters > Mesh > Flatten... to combine the two meshes.

* One problem you may run into is that the Voronoi Tesselation seems to mess up at the join between the neck and the bottle. To avoid this, use Filters > Cleaning > Merge Close... and set a pct of 8-10 (Try 8, if it doesn't work, backtrack and try bigger numbers.

* Save the results and then do the Voronoi tesselation. See my Voronoi Tetrahedron for the details on how to do that.

Monday, August 26, 2013

Voronoi-tesselated Tetrahedron

I'm enjoying playing with mathematical objects and printing them. Yesterday I created a Voronoi-tesselated tetrahedron. Halfway through the print I dropped some bells into the central cavity to make a baby-rattle. The object is now on Thingiverse if you want to make one.

My starting point was a blog post showing how to do Voronoi Tesselations in MeshlabHowever, Meshlab is a bit crashy, so I had to do some experimentation. Here is the general procedure I came up with -- hope it helps you create some nice objects.

Launch Meshlab

Make sure Selected Face Rendering is on.. It's the icon with red in it to the right of the light bulb icon.

File > Import Mesh to import your nice fine WATERTIGHT mesh (otherwise, expect bad things to happen), or Filters > Create Mesh Layer > ... to start with a primitive (like the Tetrahedron)

Before you go further, you need to make sure that your object is properly aligned to the XY plane. Click the Wireframe icon (next to the dots icon, then rotate the model (left-click drag it) until there are 3 points that you want to be on the base of your model located where you can drag a marquee over just those points, then click the Select Points icon (next to the Rabbit icon) and do just that.  Then use Filters > Normals... > Transform: Rotate to fit on a plane, check both options and apply.

If you don't have enough vertexes (100-300k is good), use Filters > Remeshing > Subdivision: Midpoint (for primitives) or Filters > Remeshing > Sudivision: Butterfly (for more complex objects) to add triangles. Always set Iterations to 1, you don't want to get too many triangles. Also Edge Threshold to 0.

Click Layers icon (looks like a stack of paper) to show layers.

Filters > Sampling > Poisson-disk Sampling. Number of Samples = 50 to 60. Click Apply, and a new layer will appear in the layers list.

Click on your mesh object in the Layers list so that it is hilighted in yellow. After the sampling, it won't be.

Filters > Color Creation > Voroni Vertex Coloring. Check BackDistance. Click Apply. Your object will get nicely colored with Voroni cells.

Render > Color > None. The colors will disappear. You do this so that the next step is easier to see.

Filters > Selection > Select Faces by Vertex Quality. Check Preview. Slide Max Quality all the way to the right. Slide Min Quality left until you get nice thin borders -- but not too thin. Click Apply.

If the lines are not GREY, use Filters > Selection > Invert Selection. Click Apply. Lines will go grey, areas between them will be red.

Filters > Selection > Delete selected Faces. Now you have a holed, but flat, object.

Filters > Smoothing > Laplacian Smooth with Iterations = 3 to 5 will give you much smoother lines.

This is good place to save a checkpoint. File > Export Mesh AS... NOT File > Export Mesh, which will copy over your old file!!! Save it as a .stl.

Filters > Remeshing > Uniform Mesh Resampling. Precision 1%, Offset 53%, check Absolute Distance. Now wait a bit, and you'll get your thick version of the object. If Meshlab crashes, you probably had a bad initial mesh, it's quirky -- and you're screwed.

In the Layers panel, click on the eyes next to your original object and your Poisson samples to turn them off. You'll only see your new offset mesh.

Filters > Remeshing > Quadric Edge Collapse Decimation. Set the target to be .75 of the original number of vertexes. This smooths things out.

Repeatedly apply Filters > Remeshing > Curvature Flipping Optimization until the object is not getting any better (it may settle down to toggling between two states).

Now you want to increase the number of triangles and make them smooth. Alternate between these two:

Filters > Remeshing > Subdivision: Butterfly, Iterations = 1, Edge Threshold = 0.


Filters > Smoothing > Taubin Smooth

When you get to the number of vertices you think you need, Export As... and save your STL.

Oh, in the case of primitives, they will only be 1mm in size, so use Filters > Normals... > Transform: Scale to make them bigger before saving. The limit is 10x, so maybe do a 10x and a 2x = 20x.

Friday, April 19, 2013

Embossing of Text and Graphics for 3D printing

So I have a new toy, an Ultimaker 3D printer, and I'm climbing the learning curve of how to use the printer and related software.

As some of you may know, I'm a 3-term member of the EVE Online Council of Stellar Management, and as it happens I'm about to go to Iceland for EVE's yearly FanFest. So I thought it would be an interesting project to make some embossed cards for my fellow CSM delegates.

The task at hand is this: take this image, a bitmap...

...and use it to create an embossed 3D model of the card itself. The CSM logo is a parody of the CCP Games logo, and shows the progression of a CSM delegate from blissfully elected (2-o'clock) to veteran interstellar policitian (center).

Our first step is to change the bitmap into a vector representation. A little websearching found an excellent tool,, that will do just this. The result is a SVG vector version of the bitmap.

Next, I have to import it into my 3D CAD program. I am using ViaCAD 2D/3D from PunchCad. It's $99 but there is a free trial.

Unfortunately, ViaCAD can't import SVG! But one of the formats it can import is Adobe Illustrator 8, and a free trial of Adobe Illustrator is available. So converting is easy: Open the SVG in Illustrator, then Save As... an Illustrator .ai file, making sure to save it as an Illustrator 8 file. ProTip: You can also use Illustrator to create some text, turn it into a path, and export it for embossing!

Now for the fun part! I'm not going to go into a huge amount of tutorial detail about how ViaCAD works, I'm still learning it and I'm lazy. But here are the steps.

ViaCAD has 2D and 3D modes. Get into 2D mode, and Import the Illustrator file. I found I had to uncheck all the Import Options in order to just get the raw curves and line segments. I needed to do this because the little stick-out-the-tongue face was too small to vectorize during the first step, so it came out as a circle -- by keeping everything separate, I was able to select and delete it. Also at this point, you want to measure your drawing and use the Scale tool to get it to the size you really want.

Go into 3D mode, go into Isometric view (or rotate the viewpoint) and use the Extrude Solid tool to create an extruded object. With nothing selected, click on the tool, then click-drag a rectangle around the stuff you want to extrude, wait for it to select, click on one of the lines, and then wiggle the mouse until you see that it'll be extruding in Z. Click again, and what do you know...

Now back to 2D mode. The next step is to add the perimeter of the card, and also the small hole where a lanyard clip might attach.

Then we extrude them as well. The one thing to be careful about is to extrude the base plate only 1.5 mm -- the thickness of your card. The initial thickness is set by how far you move the mouse when selecting the axis of extrusion, but there's a modeless dialog you can use to set it.

Next, we use the translate tool to move the logo and hole in Z. We move the logo up 0.05 mm so that the bottom of the logo is 2/3rds embedded in the card, and the lanyard hole down 1 mm so that it fully  intersects.

Finally, we use the Subtract Solid tool to subtract the two solids from the card, and we have our finished 3D model.

Now we can export a STL file and load it into our slicing software. In the Mesh Parameters dialog that appears after you select a file name, I checked STL Facets but I have no idea if that's needed.

I am using Cura to do my slicing for me. So far, the best results come from using a raft (to prevent warping), the thinnest possible wall thickness, and 100% fill density.

Here's the final result.

My next task is to find some sort of infill material I can put into the emboss to give it a different color. There are many possibilities, like this.

Wednesday, December 19, 2012

Add a rear-view camera to a 2012-2013 Hyundai Elantra for $80 and a couple hours of labor

We recently bought a 2013 Hyundai Elantra as an extra car for She Who Must Be Obeyed, and in particular, for Sarcastic #2 Son to use to drive to school. My wife loves the rear-view camera in our Chevy Volt and wanted one in the Elantra, but the factory camera is only available in a particular option package we didn't need. The dealer told us that aftermarket installs cost $800 or so, which I felt was a bit excessive.

So I did some research, and ended up at AliExpress, the consumer portal for the big Chinese B2B site Alibaba. What I found was quite interesting; if you're willing to do a little research, you can obtain and install your own camera system for about $80, and install it in about 2 hours.

What you need are:

  • A rear-view camera with wireless transmitter and receiver (otherwise you'll be stringing cable from your trunk to the front of the car). I found this one for $40 that is specifically made for the 2012-2013 Elantra. If you have a different car, you can find one that fits yours and adapt these instructions.
  • A small LCD panel you can mount in the front of the car. There are zillions of them; I picked this one for $35 because it would fit nicely into the dashboard in the pocket which contained the cigar lighter socket and also had a suction mount, in case I changed my mind.
  • A cigar lighter adapter plug that terminated in a standard jack. I happened to have one in my junk box. If you have one that doesn't have the right jack, you can just splice it directly into the LCD power connector. Make sure it's a basic one that isn't doing any voltage conversion!
  • A couple of tap splices for grabbing power from the rear backup lights.
  • Two pair of wire connectors of some sort.
You will also need some basic tools:

  • A Philipps screwdriver.
  • Wirecutters and strippers.
  • Pliers.
  • A soldering iron.
  • A multimeter.
Expect that the parts coming from China will take about 3 weeks to arrive. Did I mention postage is included? When they do come in the mail, check them to make sure they work, and then log on to AliExpress to confirm receipt (the seller does not get paid until you're happy).

Here's my breadboard setup, using a 12v battery.

The center nipple on the cigar adapter is positive (+), and the springy things on the side are negative (-). To assemble the LCD screen and video receiver, you cut one of the wires coming out of the plug, strip both ends, and test it to see if it connects to the center nipple. If so, you twist the two ends together again, along with the red power wire from the receiver. If not, you twist them together with the black wire. If you get it right, when you apply 12v of power to the cigar adapter, the green light on the receiver will light up. The LCD screen may brighten a bit, but it won't show a picture unless the transmitter is on and sending something.

Solder the wires together and insulate them with tape, plug the cigar adapter plug into the red power plug of the LCD, and the receiver output into one of the video inputs (most of these LCDs have two inputs, it doesn't really matter which you use unless you also want to use the screen for other things).

When you're all done, you'll have something that looks like this:

Now out to the car. Pop open the trunk and take a look at the plastic bolts holding the top liner to the trunk lid. Unscrew them most of the way and then they pull right out. They consist of a central bolt and an outer flange. To replace them when you're all done, just unscrew them completely, squeeze the outer flange tabs a bit, insert it through the liner into the trunk lid, and push the bolt back in -- no screwing required!

You'll have to twist around to see the square cover that hides the hole where the camera goes. Just squeeze the tabs one at a time and wiggle and it'll come out. Remember to save it in case you need to restore the car to factory condition (such as at the end of a lease).

Here you can see the hole from the outside. When the trunk is closed, the hole is parallel to the ground.

The camera has two small tabs on one edge and a big spring-tab on the other edge. You just feed the wires through the hole and click the camera into place.

Now for the slightly tricky part. Find the connector that powers the white backup and red brake lights. It has 3 wires, black, green and blue. Remove it by squeezing a tab and pulling it gently -- a small pair of pliers makes this much easier, because it's in an awkward position.

Use your multimeter to figure out which wires feed the backup lights (not the brake lights!). These lights are on anytime the car is in reverse. On the Elantra, the blue wire is positive (+) and the black wire is negative (-). Check carefully; I got it wrong the first time, which is why I connected a red wire to the negative lead. Get a couple of short lengths of 14-gauge wire and use the tap splices to connect into the car's wires. Don't connect the transmitter power wires directly; they are too small and you may not get a good connection!

To use a tap splice, your new wire goes in the completely closed hole in the splice, and the existing wire slots into the half-open slot, then you push down on the metal tab with pliers.

Once you've done this, put connectors on the other ends of the wires, and also on the power wires coming from the transmitter.

Plug the transmitter into the camera (video and power), and connect it up to your new power wires. Then get someone to turn on the car and put it into reverse; you should see the power light on the transmitter come on.

If at this point you get run over, either you're an idiot or someone doesn't like you very much.

Now go and plug your receiver assembly into the cigar plug in the dashboard. If all is well, a second or two after you put the car into reverse, the LCD will light up and show you what's behind your car.

Assuming all is OK, go back and thread all the wires in the trunk lid nicely, and use cable-ties to keep everything neat and in place. In particular, position the transmitter so that when the trunk is closed, the little antenna has good line-of-sight to the receiver in the front of the car. Conveniently, there are two small holes in just the right place to make this easy.

Oh, and don't forget to plug that connector back into the lamp assembly before you put the put the trunk cover back on! And to test it to make sure you haven't messed up the lights.

Then all that remains is to tidy up the cables in the front of the car. For now, I'm just tucking them behind the LCD screen, which just fits in the little compartment in front of the gearshift, but next year I plan to get a 3D printer and may fool around with making a custom mount.

The only thing that isn't quite perfect about this setup is that the camera seems to be tilted a few degrees off the horizontal. I may be able to fix that by fiddling with it a bit, but for now it's perfectly acceptable.

Hope this little tutorial helps a few people out!

Saturday, November 26, 2011

Experimental flight results!

Here are two videos showing the results of the high-speed videography. My thanks to Michelle Peters and the rest of the Zero-G crew for their help in getting everything to work.

I'll be posting videos of the basic physics experiments in a couple of weeks, lots of editing and graphics to add to them.

First up, liquid deployment tests...

And last but not least, the ever-popular Mentos in Space!