Skip to content

Yet another Bezier library for OpenSCAD

Advertising
Advertising
?
Creation quality: 5.0/5 (1 vote)
Evaluation of members on the printability, utility, level of detail, etc.

  • 1.1k views
  • 19 downloads

License
3D design format
SCAD and STL Folder details Close
  • bezier.scad
  • bezier.stl

Learn more about the formats

Publication date 2021-03-27 at 22:07
?
Published to Thingiverse on: 2017-03-27 at 16:44
Design number 346327

3D printer file info

3D model description

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 (https://www.thingiverse.com/thing:3527642) 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 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 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_REL(1)

  • 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 v

  • POLAR(r,angle): Like 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 OFFSET([0,0]) (or OFFSET([0,0,0]))

You can't have SMOOTH_*() and/or 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 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.

If you just want to use Bezier splines to smooth out the corner of a path, you can use:
PathToBezier(path,offset=2,tension=0.551915024494,closed=false)
This returns a Bezier path which rounds off each corner in the path at offset distance from the corner. The tension parameter specifies what fraction of the offset the control nodes are to be added at: the default is designed to make right angles be very close to circular arcs. You will still need to feed the resulting path into the Bezier() function to render it.

Note that REPEAT_MIRRORED() can be used (multiple times if need be) at the end of the path fed into PathToBezier: this allows you to quickly build up more complex shapes. For instance, the rounded plus board for a solitaire game (https://www.thingiverse.com/thing:4042748) can be generated with: PathToBezier([[1,0],[1,1.5/3.5],[1.5/3.5,1.5/3.5],REPEAT_MIRRORED([-1,1]),REPEAT_MIRRORED([1,0]),
REPEAT_MIRRORED([0,1])],offset=0.1)

A useful included module for debugging Bezier curves is BezierVisualize(p).

Updates:

January 8, 2020: Remove warning in newer OpenSCAD versions.

December 12, 2019: PathToBezier() added.

December 1, 2019: SMOOTH_ABS() and other functions work together with LINE() on the other side of the node.

3D printing settings

-

Tags

Advertising


Issue with this design? Report a problem.

Would you like to support Cults?

You like Cults and you want to help us continue the adventure independently? Please note that we are a small team of 3 people, therefore it is very simple to support us to maintain the activity and create future developments. Here are 4 solutions accessible to all:

  • ADVERTISING: Disable your banner blocker (AdBlock, …) and click on our banner ads.

  • AFFILIATION: Make your purchases online by clicking on our affiliate links here Amazon.

  • DONATE: If you want, you can make a donation via Ko-Fi 💜.

  • WORD OF MOUTH: Invite your friends to come, discover the platform and the magnificent 3D files shared by the community!


Sharing and downloading on Cults3D guarantees that designs remain in makers community hands! And not in the hands of the 3D printing or software giants who own the competing platforms and exploit the designs for their own commercial interests.

Cults3D is an independent, self-financed site that is not accountable to any investor or brand. Almost all of the site's revenues are paid back to the platform's makers. The content published on the site serves only the interests of its authors and not those of 3D printer brands who also wish to control the 3D modeling market.

100% secure payment by credit card, PayPal, Apple Pay, Google Pay, etc.
View all payment options.