# New Year, new tools – OpenScad Tetrahedron

I fired up OpenScad, and created a new tetrahedron model using it.  I’ve done tons with platonic solids in OpenScad in the past.  This time around though, I figured I’d create the simplest tetrahedron I know.  Here’s the OpenScad code for the same:

```hull(){
translate([0,0,0])
sphere(4);

translate([100,100,0])
sphere(4);

translate([0, 100, 100])
sphere(4);

translate([100, 0, 100])
sphere(4);
}
```

The trick here is in the fact of the special relationship between a tetrahedron and a cube. The cube has 8 vertices, and you can create a tetrahedron by using 4 of those vertices. You just have to pick the right ones. You can easily choose the right ones by picking a set at opposite corners of any face (cutting a diagonal across that face). Then, choose the face exactly opposite, and select the two corners that are different from the ones you picked on the first face. Now you have these 4 vertices.

OpenScad has had the ‘hull()’ module since forever, but it didn’t always work so well. In this modern OpenScad, and for this particular case, it works extremely well. Just take the 4 vertices, throw them into a hull(), and out comes a nice tetrahedron!

This is the tetrahedron for the masses. No math required, except to know the vertices of a unit cube. And of course you can scale it up to any size you please.

If you want to do anything tricky with it though, like subtract some holes and the like, you’ll have to know the math again. But, there you have it, tetrahedron solid in a few lines of OpenScad.

# Supporting the Next Industrial Evolution

A long time ago in a galaxy far far away… I was in business with my brother.  We did software, on odball platforms such as NeXT and BeOS, until I left for a job in the Pacific Northwest.  In the past couple of years, we have been having discussions about the economy, and where jobs have gone, and what can be done to create new jobs.

One of the thoughts that I’ve had on the matter is that certain types of jobs are rapidly disappearing, like heavy manufacturing.  A lot of these jobs are disappearing because of automation, or shifting labor rates, or shifting raw materials, or simply the needs of societies are changing.  Moving out of coal, more into natural gas, so less coal miners needed.

One of the things that’s been changing most recently is what I’ll call the democratization of manufacturing.  When you can purchase a “computer” for \$250 (lastest Samsung ChromeBook), and you can purchase an assembled 3D printer for less than \$1,000, you’re suddenly got in your hands the tools to begin micro manufacturing.  You can both create the appropriate design files, and with a reel of plastic, you can print off your own versions of things, locally.

This sort of scenario is being played out time and again in Maker Faires, NYTimes articles, Wall Street Journal and the like.  There is a lively community of makers in the world, and they’re all kind of chanting in the same way “We want to make our own stuff”.

One aspect of the maker community that is true for me is that my design skills are somewhat limited.  I’m not a SketchUp user, nor will I ever master SolidWorks, or anything remotely like that.  But, I know people who are experts in that stuff.  I’m an expert in certain kinds of software development.  Of late, I’ve been focused on things related to cryptography, identity, and network services.

What does this have to do with democratization?  Well, it occurs to me that the way the world is headed is more about mash ups of different skill sets, combined with a proliferation of relatively inexpensive manufacturing tools.  Once anyone on the street can get something designed to their specifications, and get that object manufactured within a reasonable amount of money, and a reasonable amount of time, we will be engaged in a new paradigm for manufacturing.

My brother’s latest venture (without me) is the pursuit of a first step along this path.  His company (Adamation) is a design firm, which is focused on the rapid development of customized products that can be rapidly manufactured.  By ‘rapid manufacture’, I mean 3D printed in most cases, at least to start.  They’ve just launched their new web site, which is a collaboration of artists from the gaming industry, along with visual artists, web designers and the like.

What they have to start is a series of completely original figurines.  There are 20 new figurines in total, which are bunched into 4 groups, with 5 characters in each group.  Each group has a unique story, and all the characters have individual bios.  You can go to the site, click on stuff, see some visuals, rotating animations, and the like, and ultimately make a purchase.

Now, I think this is really cool, not just because it’s my brother doing it, but because this is how I think goods should be.  Right now, each of the figurines comes in 3 different poses, but I know they have plans to allow the user to customize them further, creating a figurine that is as unique as the user desires.  This is customized manufacturing.  The figurines are printed ‘just in time’, so there’s no inventory.

I could gush on about these things, but I’ll just encourage you to go check out the site if you’re interested in such things.

This does bring up another thought in my mind though.  There are a lot of people thinking about how best to bring about this industrial revolution.  There are tons of little companies working on 3D printers.  Lots of people working 3D printable models, and lots of individuals dreaming about how to pull it all together.  The pieces are out there.

When I look at the current landscape, I see things like small electronics companies (SparkFun, SeeedStudio, AdaFruit), and their ability to crank out small scale electronics kit.  Then there’s the oh so popular for the moment Raspberry Pi, which brings some compute to the table.  Then there’s tons of people focused on creating cases for electronics, and these 3D printer people, who can make just about anything to pull stuff together.

Perhaps what’s missing is the spark, a true vision to help guide things.  Perhaps there’s some amount of funding that needs to be flung into some of the dimmer corners to bring out true innovations.  Some of this happens with KickStarter projects, but there’s probably more to be done.

I was happy to help my brother get started in this little venture by providing capital so that he could purchase the means of production.  Not a fortune, but more than I had in my piggy bank.  Perhaps what’s needed here is more people coming together collectively to fund the creation of new design firms, new design software, new micro manufacturers.  Just a thought.

At any rate, I’m happy my brother’s company has reached the stage where they can start talking about it openly in the world.  I’m sure it will be a success, or at the very least, very provocative.

# And Height Maps for all…

How can there possibly be 3D modeling and visualization without height maps?

Of course, Height maps have been a staple of 3D graphics for quite some time now.  Why not extent this to 3D modeling for printing?  In this case,  I have created this nice generic RubberSheet object.  A RubberSheet is a BiParametric with a size.  So, it’s just a convenience wrapper on the BiParametric.  It assumes a basic X,Y grid, but then things get really strange.

Of course you can give it a number of steps to iterate in each of the axes, and you can give it a color sampler as well, and you can give it a VertexSampler.  What?  Yah, of course, you can just hand it a routine which will calculate the vertex at the particular grid point.  On its own, it will just lay out a flat grid, with nothing interesting on it.

This is using the standard ImageSampler.

```local colorSampler = ImageSampler.new({  Filename='firstheightmap.png',  Size = size,  Resolution = res,  MaxHeight=64, })

rubbersheet({  Size=size,  Resolution=res,  ColorSampler = colorSampler   })
```

But, what if I used the color sampler for both the color at a position, and for the x,y,z value as well? After all, it’s pretty easy to calculate the x and y, values. And the z could be calculated by taking the luminace value (gray) of the color pixel, and using that as the height. In fact the code is as simple as this:

``` function ImageSampler.GetVertex(self, u, w) local col = self:GetColor(u,w) ```
``` -- Turn it to a grayscale value local height = luminance(col) ```
``` -- Multiply by max height local x = u*self.Size[1]/self.Resolution[1] local y = w*self.Size[2]/self.Resolution[2] local z = height*self.MaxHeight local vert = {x,y,z} ```
``` return vert, {0,0,1} end ```

The ImageSampler is a functor. That is, it’s an object that has some state, and it can have simple functions called. At any rate, since I’ve implemented ‘GetVertex’, and the BiParametric object calls GetVertex if you tell it what VertexSampler to use, you can now do the following:

``` rubbersheet({ Size=size, Resolution=res, ColorSampler = colorSampler, VertexSampler = colorSampler, Thickness = -10, }) ```

As an added bonus, you can set the Thickness property, and automagically get a rubber sheet with the specified thickness, which makes it printable. This will create a rubber sheet that will follow the contours up and down. If you want a base plane, then you’d alter the lengths of the normals to be a reciprocal relationship to the height, but that’s a silly way of doing things, even though it would work.

And, there you have it. Height maps with ease. And, since it’s integral with the color Sampler, you could easily add colors based on the height value, for instance to have snow at the tops, brown dirt below that, then greenery at the bottom.

# Tactile Math Explorations

Although I took math in high school and college, my math skills have atrophied over time due to lack of usage.  How can I possibly do 3D graphics if I can’t remember the math?  It takes a lot of referencing back to books, and code I wrote years ago.  So, perhaps there’s a better way of teaching some math skills which will make the lessons stick?

Here we see 3 of the quadrics.  The cone, cylinder, and hyperboloid.  Each of them has their own bi-parametric equation that describes them.  In this particular case though, I’ve used only one formula to describe three different shapes.  I have used the Hyperboloid, because by slightly changing various parameters, you can get all three shapes.  The Banate CAD code looks like this:

``` local usteps = 180 local wsteps = 80 local radius = 5 local height = 10 ```
``` local con = {{radius, 0, 0}, {0, 0, height}} local cyl = {{radius, 0, 0}, {radius, 0, height}} local hyp = {{radius, 0, 0}, {0, radius, height}} ```
``` function hyper(params) hyperboloid({ USteps = usteps, WSteps = wsteps, StartPoint = params[1], EndPoint = params[2], --ColorSampler = checkerboard:new({Columns=usteps, Rows=wsteps}) }) end ```
``` color("Red") hyper(con) ```
``` color("Green") translate({12, 0, 0}) hyper(cyl) ```
``` color("Blue") translate({24, 0, 0}) hyper(hyp) ```

In the beginning there, I setup the radius, height, and resolution I’m going to generate the curves.  Now, the hyperboloid takes some explanation.  Of course you can look it up online, but the thing to realize is that you take a line, any line, and sweep it around in a circle.  for the simplest case, the cone, just take a stick, stand it straight up on your desk, some distance from the center of your circle, and move it around that center.  You have just traced out a cylinder in space.

Now, let’s say you want to make a cone.  Take that stick again, and instead of it standing straight up and down, lean it in towards the center.  Now as you sweep it around, the top part stays fixed, as the bottom traces out a circle.

And lastly, for the hyperboloid, tiltl the stick slightly back, and to the left, and again, trace it around.

This is kind of hard to describe in words, and some visual aids would sure make it easier.

I’ve done exactly the same thing here, execept I’ve changed the resolution to make the facets more obvious.  Now if you go back and read the explanation again, it might make a little more sense.

In each case, all I’ve done is change the starting and ending points for the stick to be traced around the circle.
``` local con = {{radius, 0, 0}, {0, 0, height}} local cyl = {{radius, 0, 0}, {radius, 0, height}} local hyp = {{radius, 0, 0}, {0, radius, height}} ```

Each of these little arrays defines a starting and ending point for the hyperboloid function.  The con (cone), has a bottom radius of ‘radius’ and a top radius of 0.  The cylinder maintains the same radius at the bottom and top.  The hyperboloid maintains the same radius, but with a twist as it shifts from the x-axis to the y-axis.

This is a nice revelation.  For the code itself, it means that I don’t actually have to write three different functors to represent these things.  I can write just one, the hyperboloid, and just change the parameters I feed it in order to get the others.  Same for ellipse/sphere.  A sphere is just an ellipse where the two axes are the same length.

How does this help me learn maths?  Well, I can write the hyperboloid equation on paper, or better yet, plug it into a graphing calculator, and play around with the results.  Better still, I can plug it into Banate CAD, and see it on the screen in real time.  And even bestest of all, I can lower the facet count, and print these out so I can play with them in my hands.  It’s this latter case that’s the most exciting to me.  If I can make maths a tangible physical thing, then I’m more likely to remember it.  A set of these hyperboloid relatives, printed out as play things, would really help me retain and understand the math behind them.

# Improved Tubing Connector

The first version of the tubing connector looked nice, and was functional in theory, but it was a bit challenging to actually print on my Up! printer.  There was an ‘overhang’ which required the use of support, and that’s kind of a waste of plastic on such a small piece.  Besides that, it was hard to print at very small sizes.

I made a couple of improvements to the design

So, now there is Flanged Connector – V2.  On this connector, there is a cylinder located at the hub.  This provides a nice strong flat spot from which the rest of the print can be supported.  Also, the tubing coming from that center out to the flanges is now the same diameter as the widest part of the flange.  This ensures there is no overhang for this portion of the object.  This design is much easier to print than the first one, even down at smaller sizes.

One of the challenges is that with small sizes, depending on your printer, there might be support material inserted inside the tubing.  That’s very hard to get out.  But, if you’re just using them as connectors, and not flowing liquid through them, you can just leave the support material inside.

I have used the connectors to form my favorite tetrahedron, albeit in spherical form.  This is vinyl tubing with a 1/4″ interior diameter, and the connectors were done with a 5/16″ outer diameter.  The fitting is snug for hand pressing.  The tubing is removable, but won’t come off easily.  I imagine that if I had used a spot of glue, it would be permanently affixed.

I am very pleased with the outcome of this design.  It is a useful item, that required only 2-3 hours of work between the first and second, and third iterations.  Now I have something added to my little toolbox of bits of plastic that can be used to do interesting things.

# Useful Household Items – Drip irrigation connectors

One of the first things I did when I purchased my Up! printer was to think about how it could be used to produce little things around the house.  To wit, I designed things like the electrical outlet cover plates, and other things with the ‘athome‘ tag on Thingiverse.

although it is very interesting to design many things that can be used in the home, sometimes it is not practical to actually print them out.  For example, the light switch cover plate, in order to print it requires quite a lot of plastic.  Given that these can be purchased for relatively cheap, since they’re so common, it’s not particularly cost effective to print at home.

But, other items make more sense, either because they are scarce, or so unique that you could not get them otherwise.  I recently pursued creating such an item.  It is the Flanged Connector.

There are several uses for this connector.  The most basic is to use it as part of a drip irrigation system.  You would insert this into the end of a piece of drip irrigation tubing.  Since it is hollow, it will allow water to flow through with ease.

When I designed it, I wasn’t actually trying to create something for drip irrigation.  I was after being able to easily connect drinking straws together.  I had purchased this book: Messing Around With Drinking Straw Construction.  I wanted to construct some structures with my daughter.  The method of connecting the drinking straws was to insert paper clips into the ends of the straws.  Where multiple straws came together, there were multiple paper clips interlocked.  It was that or pin, or tape.

As a general mechanism, it has the advantage of ease, and low cost.  Paper clips are readily available by the thousands, at relative low cost.

But, we found the technique to be a bit cumbersome.  The straws were not stiff enough, and the paper clips could not hold shape at the vertex, so it required multiple hands, or support to keep the structure from simply collapsing until the thing was entirely finished.

I wanted a better way to connect the straws, and at the time (around 2004), I was dreaming of a simple connector that I could stick into the ends of the straws.  I contacted an injection molding outfit, but they wanted a few thousand dollars to develop the design, do the mold, before anything was actually created.  I pretty much left that idea behind and bought quite a few Zome Tools instead.  That construction set worked quite well, and was more than sufficient to meet our needs.

Recently, I have been cleaning out the house, in preparation for a move, and came across the bundle of about 1,000 straws I had purchased so many years ago.  That bundle reminded me of the little connector that I wanted to create at that time.  Now, 7 years later, I actually know how to use 3D design tools, at least OpenScad.  Now I realize that what I want to create is a simple matter of a few odd shaped cones and cylinders, attached at various angles.

After going back and forth on a few design iterations with Sjoerd de Jong, there now exists a ready made library of routines to construct just about any type of vertex you want.  The Vertex Generator allows you to create vertices for a few well known solids, as well as create vertices of your own.  It utilizes some vectors that you pass to a routine, and it does the rest.

One of the things that I wanted from that library was the ability to separate the printing of the arms from the vertex math itself.  The library goes far down this path, and you could imagine replacing the ‘rod connectors’ with these tube inserts instead.

But, not needing the full generality of that library, I decided to start from scratch and create this imple connectors.  My requirements were that I could stick them into straws, as well as vinyl tubing.  I also wanted there to be some ready made connectors for common tasks.

I start with a straight connector, which can be used to simply join two pieces together in a straight line

This comes from the print_connectors(num) module.  Basically, the ‘num’ parameter is the number of connectors you want to be connected.  In this case, it was a simple matter of calling it: print_connectors(2);

You can call it similarly with any number of connectors.  There is a global parameter ‘standoff’.  This is the amount the based of the flanged connector is offset from the origin.  In the case where you have a high connector count, like 8, you might want to increase this size to accomodate the multiple connectors.

In this case, I used print_connectors(8); and ‘standoff=10;’.  This leaves enough space for the tubing to slide over the connectors, as well as get pretty close to the hub.

The ‘print_connectors()’ module is fairly handy when it comes to creating a set of connectors that are spread evenly around the hub.  There are some cases where you might like to specialize though.  Elbows are acommon connection type, as are ‘T’s and risers.  The library currently includes a module to create elbows.

Here, there are two elbows.  The first is specified with ‘print_elbow(angle=90, \$fn=24);’, the second is printed with ‘print_elbow(angle=120, \$fn=24);’.  In this way, I have specialized for the case of printing two connectors with an angle between them.  Really, this could be generalized to specify any number of vectors in a list, and let the print_connectors() module do the right thing.  That may be an exercise for the next round of these routines.

The really nice thing about this design is the hollow tubing.  Meaning, these are like pipe connectors, in that they will allow liquid to flow through the connector itself.  That ‘liquid’ can be anything.  One example might be colored water that is placed inside the straws, just to make things look interesting.  But, it’s just an open space.  These connectors could easily be used to route cables, with attached conduit.  You could use vinyl tubing to route wiring in a device, and put a little bit of elwire in there as well to light up the path.

One other Idea I had, for forming rigid framing, is to use vinyl tubing to connect things, then fill the tubing with some hardening foam, or epoxy, or something else that can first flow as a liquid, then harden into something much more strong and rigid.  That might be a great way to ship some simple structure, and assemble it without having to worry about long strong members.

Lastly, printing these things, although relatively inexpensive, is quite challenging.  The amount of overhang, and the tiny proportions, will challenge most DIY 3D printers of today.  Ideally, this would be injection molded, which was my original intentions.  But who knows.  Over time, being able to render such a design, inexpensively, and quickly, at home may become a reality fairly soon.  When it is more feasible, I can imagine the joy children and adults will have when they want to create a new toy for themselves, they go to their insta-printer, and out comes the results they expect.

# Revolutionary Surfaces with OpenScad

I have spent quite a lot of time with OpenScad, adding functions and whatnot.  One of the lines of improvements that I’ve been pursuing has been surfaces in general, and more recently surfaces of revolution.

Starting from the work I started with Bezier surfaces, I had first constructed basic surfaces of revolution based on simple functions, and thus began the revoloids campaign.

Having remembered some basic high school math, I was looking to generalize the idea of surfaces of revolution, so I started down the path of using cubic curves to describe surfaces of revolution.  This was an interesting path to pursue because along the way I wanted to also simplify the Bezier calculations that I was using.  As it turns out, you can specify cubic curves (which represents a broad set of curves) utilizing a simple matrix representation.  Through consultation with my various old graphics books, I was able to come up with the generalized routines to represent cubic curves.  As a result, the surface of revolution based on cubic curves can represent any cubic curve.

I encapsulated the latest of this work into the revoloids library.

In the latest incarnation of the library, I added the ability to specify a starting and ending angle for the surface.  This is nice because although you could generate the whole surface, and then slice off a bit using CSG, sometimes you actually know exactly what you want, and using CSG operations is just a waste of time.

The general mechanism I am using to render these ‘solids’ is to construct a giant piecewise polyhedron one quad at a time.  The benefit of this method is that it can be used to represent any type of 3D object, on the fly.  The downside, with respect to OpenScad, is that these objects do not play well with other objects from a CSG perspective.  Rather than seeing a piecewise polyhedron, what OpenScad really wants is a single object, with all the vertices specified, and then the faces specified from that single vertex set.  The real challenge here is that OpenScad does not have any mechanism whereby you can specify a whole bunch of vertices on the fly.  You have to construct them up front, or generate a file.

This isn’t really a limitation though, it just shows the boundary of what you can do from within the context of the OpenScad editor.  Since my math routines are fairly generic, and don’t really rely on anything within OpenScad, it will be a fairly straightforward exercise to rewrite them in ‘C’, or even javascript.  By doing such, I could simply generate the correct polyhedron, and then export it as OpenScad.

This is a generic technique I want to pursue.  Basically, construct a series of simple executables which can be chained together, with OpenScript as the final outcome.  This is what happens with the font importer utility, as well as the polygon generation flash tool.

Through this experience I have contemplated a couple of things:

OpenScad is a few things.  A domain specific language, a wrapper of other libraries.

The actual CSG work is done in CGAL.

As much as I like the OpenScad language for ease, I prefer to have a stronger language

OpenScad can have an ‘extensions’ model whereby modules that are quite useful are created and disseminated.  Right now this happens with the ‘library’ directory, but there’s not much there.

But, these are just random thoughts.  What I’m really contemplating, and currently pursuing, is implementing my routines in JavaScript, and operating in the browser, or another host.  If in the browser, then it would be WebGL.  This seems to be a quite reasonable way to go.  WebGL and HTML 5 seem to be all the rage these days.  That would give any application the ultimate reach, without having to worry about libraries such as Qt.  The biggest challenge is dealing with the CSG routines that are implemented in CGAL.  If that can be cracked, then it becomes a relative no-brainer to create an OpenScad like experience in HTML.

Besides that, the other thought is, implementing these routines directly in the 3D printer.  There’s really no reason in the world why the printer (given sufficient processing power) could not take a .scad file description, and render directly from there.  That’s another line to pursue.

At any rate, for now, these surfaces of revolution are ‘feature complete’.  I will fold these routines into the Renderer and move on to the next set of routines, which have to do with surface intersections.