April 6, 2016
Description
I was working on a project in OpenSCAD that needed smooth curves. I was excited to find some Bezier curve libraries, but as I used them I remembered why awkward thing about Bezier curves: they're hard to design with if you want precise control. You move a control point, and it pulls the curve one way, but it also affects other areas of the curve, so you have to nudge adjacent control points the other way to compensate, and then repeat forever.
What I wanted was to tell OpenSCAD exactly where I wanted the curve to go, with a few points, and have it make a smooth curve passing between those points. That's a spline. I couldn't find any spline libraries for OpenSCAD. So I made this one.
The main module, spline.scad, is directly usable with no other dependencies. Grab the zip file instead if you want to look at the examples, as they're dependent on a couple of other modules.
Sadly, the noodles look pretty great in the preview, much of the time, but the current OpenSCAD code chokes on them while rending with internal assertion failures, especially if you do Boolean operations with other shapes. The other shapes compile fine, though, and reasonably quickly.
Also, the approach to cross-section orientation I'm using in the lofting algorithm sometimes breaks at sharp transitions. Some of this could be fixable without changing the interface; some of it may require manually specifying normal vectors at each path point. I'll work more on that.
I welcome your input if you want to work on these problems. Feel free to fork the code from my GitHub.
Also: I developed this using OpenSCAD 2016.02.09 and it uses some recent features, so it won't be compatible with older versions. OpenSCAD has been backward-compatible in my experience; if anyone has a reason to prefer an older version, I'd like to hear about it.
License:
Creative Commons - Attribution