This is yet another Bezier library, which takes a list of nodes and control points and generates a list of points that you can then feed into polygon() or some other function. The Bezier curves can be either 2D or 3D, but I've only been using it for 2D.
The library is designed so one can lay out 2D Bezier curves basically in one's head. But if you prefer to lay them out graphically, you can use Inkscape plus this plugin to design Bezier curves for this library.
One of the things I wanted was the ability to have an easy way to include smooth control points--control points that ensure that curve through the node has no cusp.
To use, first do
use <bezier.scad>; and then call the function
Bezier(pointList) to generate output points. There is an optional
precision=x parameter. With that parameter, about
1/x points will be generated per segment (excepting 2D segments that are a straight line--these are optimized to two points). Default is
pointList is a list of points arranged as follows:
I recommend that in your code you flag the control points with
/*C*/ so you don't get lost in a long list of points.
Each segment of the Bezier curve consists of two nodes, with two control points in between them. You can also have these special control points:
SYMMETRIC(): This makes the control point be on the same line and at the same distance to the node as the control point on the other side
SMOOTH_REL(x): This is like
SYMMETRIC() except that the distance of the control point to the node is
x times the distance of the other control point to the node (can be negative for special effects);
SYMMETRIC() is in fact shorthand for
SMOOTH_ABS(x): This is like
SYMMETRIC() except that the distance of the control point to the node is exactly
x (can be negative for special effects)
OFFSET(v): This makes the control point be at the neighboring node plus the vector
OFFSET(v) but specified in polar coordinates; equivalent to
OFFSET(r*[cos(angle),sin(angle)]); only works in 2D
SHARP(): Puts the control point at the neighboring node; equivalent to
You can't have
SYMMETRIC() control points on both sides of a node--the library then wouldn't know which line to place the control points on.
Finally, at the end of your list of points (and only there) you can add one or more
REPEAT_MIRRORED(normalVector) points each of which stitches at the end of the path what came before but reflects it in the direction of the
normalVector. For instance, if you want to draw a rounded plus sign, you can just include the first quarter, and then two
There is also a utility function
DecodeSpecialBezierPoints(p) which takes a node/control point list
p and decodes all the special points (
SMOOTH_*(), etc.) into ordinary 2D vectors. This is useful if, say, you want to take a Bezier curve and transform it in some way.
See the sample polygons in the source code for examples.
A useful included module for debugging Bezier curves is
Updates: Support for 3D curves.