I am trying to replicate a model I have created in Rhino + Grasshopper in
OpenSCAD (see image below).
The model has a few features I can control by changing a parameter.
1) the twist angle
2) the amplitude of the ripple
3) the frequency of the ripple
In Grasshopper I constructed the model by creating an array of alternating
bigger and smaller cross-sectional squares and creating a loft surface
through each of them.
When I want to change one of the mentioned features I do the following:
1) Twist: rotated each square in the array
2) Amplitude: Change the scaling of the smaller squares relative to the the
3) Frequency: Since the height is fixed, changing the number of
cross-sectional squares will change spacing
I feel like OpenSCAD has a pretty steep learning curve so I am turning to
this forum looking for some tips on how to proceed.
1) Is, what I am trying to model, feasible?
2) Should I change the way I construct my model? Is there a better way?
3) If so, what libraries should I be using?
4) Any other points of constructive criticism?
Thanks for giving me some example code. I can tell you have made an object
tier which is a union of a cube and a cuboid. Even though I have added the
BOSL library to my libraries I can not get it to render. For some reason I
just get a stack of cubes and the cuboids seem to be missing (see image
If this project is your entrance to OpenSCAD you have chosen a very ambitious
problem that can't be tackled with the usual means of OpenSCAD.
linear_extrude() is not equipped for extruding objects with varying
diameter. It can do twist and a scale but the latter is a linear function it
calculates on its own. You want to specify a scale function.
Of course, your problem has a solution in OpenSCAD if you draw on an
advanced techique (and library) that lets you do almost every thing you want
- provided you can describe it in an affine way. You create a sequence of
polygons that describe the slices of your extrusion path and then coat this
sequence into a 3D object. To create the polygons you need a shape function
allowing you to specify the (pulsating) radius and a z-height. Finally you
need an operator that transforms a sequence of polygons into a 3D-manifold
respectively a proper polyhedron call. Note that *none of the polygons may
self-intersect and none two of the polygons may mutually intersect*.
The following code is fairly simple and does everything you need. You can
reimplement the shape function to have rounded corners and so on. I omitted
this to keep the example simple. The gen() function creates the polygon
sequence in a linear-extrusion fashion and is called twice to generate the
outer and the inner wall in the same fashion, but with opposite diameter
modulation. sweep() does the coating. You can find the lib by following the
Thingiverse link. I have updated the file right now to get rid of some nasty
RC3 warnings. The lib is quite rich and to find out what it else offers you
can call its help function help_Naca_sweep() and of course have a look into
the code and the thingiverse projects connected with it. Note that the
parameter closed=true tells sweep() to extrude a ring. You set it to false
if you extrude to a monolith only.
I used the same approach in OpenSCAD, quickly discovering that lofting is
not as easy as it seems.
This is true, but
it's not impossible.
> 1) Is, what I am trying to model, feasible?
> 2) Should I change the way I construct my model? Is there a better way?
I use functions to generate polygons as lists of points, then use list comprehensions to create all the coordinates for a solid shape, and then use a skin() function to "wrap" the shape in polygons.
Here is a rounded prism library that I recently created that uses these techniques.
My (incomplete) fireflash takes things further by using splines to create objects from my control points, and also "probing" the points of the object to attach other objects. None of this is easy, and it could be argued that the CSG side of OpenSCAD is being ignored or shunned, but I do then use a lot of binary ops to chop up the object for 3D printing.
Oh, and this funny "plectrum" shape might also be of interest.
Hope this helps.
> Hi lar3ry,
> Thanks for giving me some example code. I can tell you have made an object
> tier which is a union of a cube and a cuboid. Even though I have added the
> BOSL library to my libraries I can not get it to render. For some reason I
> just get a stack of cubes and the cuboids seem to be missing (see image
Are there messages about being unable to find the library file? Most likely
you have not placed the library where OpenSCAD can find it, or used the
right path in the "use" statement. The simplest thing (to just get it
working) is to put the library in the directory with your code and make sure
that your use statement leads to a file that exists.
The method here will not give you a sinusoidal ripple but rather circular
arcs, so it sort of approximates what you want, but to really get it right
you need to use the more sophisticated sweep approach Parkinbot posted.
Thanks for putting your modeling approach in such clear writing. I agree
that my first project might be somewhat ambitious but that makes it more
interesting right? :)
Your library and example certainly is of great help. I will play around with
it a little bit while getting to know the openSCAD way-of-thinking and
I know this is off topic and if this belongs in a different thread please
say so but I have have some problems loading in the libraries. I get the
ERROR: Parser error in line 94: syntax error
WARNING: Failed to compile library
Module cache size: 1 modules
Compiling design (CSG Tree generation)...
WARNING: Ignoring unknown module 'sweep'.
It seems weird that it fails to compile the library even though it is
pointing to its exact location.
I have tried the following things to get it to work:
1) I played around with the slash (/) and backslash (\) use <lib> command
2) Save library in C:\Program Files\OpenSCAD\libraries
3) Save library in C:\Users\myName\Documents\OpenSCAD\libraries
4) Save library in folder where the code that calls on the library is saved
5) Add OPENSCADPATH=C:\Users\myName\Documents\OpenSCAD\libraries to my
6) Using the include statement instead of use
All of these attempts were based off of other forum posts but none of them
lead to anything.
Thanks for your feedback, which tells me that you are using an older version
of OpenSCAD. Which version are you using? Please try with the newest RC3
snapshot from http://www.openscad.org/downloads.html#snapshots. My library
is updated to use it. Just uploaded a version that digests versions down to OpenSCAD 2016, but not the last "official" release from 2015.
Background: They have changed OpenSCAD a lot with the last release
candidates. You get thousands of warnings on code that worked with older
versions, and to get rid of these warnings you have to use new functions
that break older versions. I look forward to the day they bring out a new