Contents
Tags
Design Tools
License
Liked By View All
Give a Shout Out
If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.
Print Thing TagSummary
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 pointscontrol 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 linethese are optimized to two points). Default is precision=0.05
.
The pointList
is a list of points arranged as follows:[node,control,control,node,control,control,node,...]
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 likeSYMMETRIC()
except that the distance of the control point to the node isx
times the distance of the other control point to the node (can be negative for special effects);SYMMETRIC()
is in fact shorthand forSMOOTH_REL(1)

SMOOTH_ABS(x)
: This is likeSYMMETRIC()
except that the distance of the control point to the node is exactlyx
(can be negative for special effects) 
OFFSET(v)
: This makes the control point be at the neighboring node plus the vectorv

POLAR(r,angle)
: LikeOFFSET(v)
but specified in polar coordinates; equivalent toOFFSET(r*[cos(angle),sin(angle)])
; only works in 2D SHARP()
: Puts the control point at the neighboring node; equivalent toOFFSET([0,0])
(orOFFSET([0,0,0])
)
You can't have SMOOTH_*()
and/or SYMMETRIC()
control points on both sides of a nodethe 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 REPEAT_MIRRORED()
items.
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 BezierVisualize(p)
.
Updates: Support for 3D curves.