Thursday, June 5, 2008

Baluster End Spacing Calculator in C#

I'm working on putting up balusters (spindles) on my deck at home, and since all the posts are spaced differently, I needed to calculate the proper end spacing for each section. Granted, it's easy enough to do this by guessing at the first length, then physically marking out each baluster width and spacing on the actual deck, and then adding the start spacing with the end spacing and dividing by two. And that's probably what I'd normally do, but I wanted to take a little break, so I made a quick app to figure this out for me.

It's a very simple app, and took about 10 minutes to write, but here's the interesting parts in case anyone is interested:

/// <summary>
/// Determines the number of balusters needed based on the top railing width
/// </summary>
/// <returns>Baluster count</returns>
public int CalculateBalustersNeeded() {
int numberOfBalusters = Convert.ToInt32(Math.Ceiling(
(this.topRailingWidth - this.spacing) / (this.balusterWidth + this.spacing)));

return numberOfBalusters;

/// <summary>
/// Determines the spacing between the post and the baluster.
/// </summary>
/// <param name="balusterCount"># of balusters used.</param>
/// <returns>Spacing at each end in inches</returns>
public float CalculateEndSpacing(int balusterCount) {
//all balusters + spacing without end spacing
float totalUnitWidth = (balusterCount * this.balusterWidth)
+ (this.spacing * (balusterCount - 1));
float endSpacing = (this.topRailingWidth - totalUnitWidth) / 2;

return endSpacing;
Nothing too exciting, really. And Excel probably would have been a better choice than a console app. But since it's all done with more or less "proper" objects (these methods are part of a "RailingSection" class generic collection that's part of a "Deck" object), I can now easily expand this into a full-blown deck design software package. Right. I guess I just can't get enough of coding at work...

UPDATE (6/13): Wow, this post is getting a lot of hits by people searching for a baluster calculator - here's the compiled EXE file: BalusterCalc.exe. You'll need the .NET framework 2.0 or higher to run it.

No comments: