Curves!

john's Avatar

john

02 Jul, 2017 10:30 PM

NOTE: This thread includes several updates. Use the updated versions of make_curve, fit_curve, and make_curve.py in the demo attached to my July 10 2019 comment, not the one attached to this comment.

Until now there were only two ways to make curves in NodeBox: quad and arc. Both create curves with control points, but define those control points for you based on simple settings. It was not possible to make a curve with arbitrary control points.

That's why I made the make_curve custom node. Make_curve lets you set the starting point P1, the ending point P2, and two control points C1 and C2. Make_curve gives you total control.

Make_curve makes it possible to do things like modify curves from an imported SVG or morph one curve smoothly into another. Or you can sketch curves directly by scrubbing the control point X and Y values.

It can often be hard, though, to calculate control point values to achieve the effect you want. So I also provide a very handy subnetwork, fit_curve, based on an algorithm by Bernhard R. Fischer.

Fit_curve uses make_curve to create a smooth curve that passes through each point in a given path. You can make the curve open or closed and adjust its "curviness". It's like the connect node except that it builds curve segments instead of line segments. My recent "Curvy Characters" post shows some of the possibilities.

The attached demo network illustrates some possible uses of make_curve and fit_curve:

  • Arbitrary Curve (center). A simple curve segment created directly from make_curve. The two red dots show the control points. Adjust values to see how it works.
  • Smooth Polygon (upper left). By feeding a polygon into fit_curve you can round its corners a little or a lot to create a wide variety of beautiful shapes.
  • Bell Curve (upper right). This example creates a histogram of a normal distribution by conducting 1000 trials of ten coin flips. Fit_curve allows you take any set of data points like this and connect them with a smooth curve.
  • Arbitrary Shape (lower left). This organic looking shape would be hard to construct in NodeBox using ellipses, quads, or arcs. The tangent lines and control points show how the fit_curve algorithm works. Adjust curviness and see what happens!
  • Spiral (lower right). Spirals were a pain to construct in NodeBox until now. Instead of using functions to calculate zillions of points and then stitching together approximations, you can just take a simple rectilinear spiral and curvify it! By adjusting the curviness you can easily create squarish spirals or elaborate spirograph designs. Great for making labyrinths, decaying orbits, or swirling text.

In addition to demonstrating possible curves, this network contains many useful subnetworks you can use in other projects:

  • controls. Draws red control points for any curve.
  • spiral. Draws a resizable rectilinear spiral with a given number of turns.
  • make_table. Converts lists of values into a table with headers that can then be filtered, sorted, etc. This version makes two-column tables but is easy to modify.
  • distribution. Given a data table, a key from that table, and a range of possible values, produces a distribution table.
  • histogram. Snaps onto distribution to plot a very simple histogram.

Enjoy!

John

  1. 1 Posted by gabriel sim-lar... on 03 Sep, 2017 10:01 AM

    gabriel sim-laramee's Avatar

    Incredible! I'm working on an illustration and this is exactly what I needed. Thank you so much

  2. Support Staff 2 Posted by john on 03 Sep, 2017 08:00 PM

    john's Avatar

    You just made my day.

    If possible, I'd love to see what you eventually make with these tools.

    John

  3. Support Staff 3 Posted by john on 28 Oct, 2017 10:25 PM

    john's Avatar

    NOTE: Attached is an updated version of my Curves demo. It contains an updated version of the fit_curves subnetwork.

    For certain paths, if fit curve was set to "closed" it would not fill correctly when colorized. This version fixes this.

    If you are using make _curve or fit_curves in any of your projects, you should replace it with the fit_curves subnetwork found inside this demo.

    JULY 10, 2019 UPDATE: I have changed the port order for make_curve and released new versions of make_curve, fit_curve, and make_curve.py. See July 10, 2019 comment in this thread for an attachment with the latest versions.

  4. Support Staff 4 Posted by Frederik De Ble... on 15 Nov, 2017 05:03 PM

    Frederik De Bleser's Avatar

    This is another super-useful node to have in core! I'll see if I can port it to Java soon.

  5. Support Staff 5 Posted by Frederik De Ble... on 15 Nov, 2017 05:10 PM

    Frederik De Bleser's Avatar

    I've added this to GitHub to track its progress:

    https://github.com/nodebox/nodebox/issues/437

    Since there are basically two types of curves in NodeBox (quads and béziers) I was thinking how you would generalize this. Then I remembered that in Houdini, you can specify the order of the curve, which allows you to set the number of control points for the curve. 0 control points will give you a straight line, 1 a quad, 2 a bézier. And you can go higher!

    http://www.sidefx.com/docs/houdini/nodes/sop/curve#parameters

  6. Support Staff 6 Posted by john on 16 Nov, 2017 09:06 AM

    john's Avatar

    Frederik,

    I am excited you are looking at this.

    If you wind up generalizing curves, you might also consider generalizing the connect node. My fit_curve subnetwork is the natural companion to my make_curve custom node - I almost always use the two together. Fit_curve works exactly like connect except with curves instead of line segments.

    I notuce that Houdini also has a fit curve node, though theirs is more complex.

    Just a thought...

    John

  7. Support Staff 7 Posted by john on 24 Mar, 2019 08:45 PM

    john's Avatar

    Frederik,

    The perfect should not be the enemy of the good. Given that all NodeBox curves are build out of cubic beziers - even quads are instantly turned into cubics under the hood - a basic cubic make curve node is all we really need.

    I am working on a library of NodeBox nodes. I try to avoid using custom nodes (Python code) unless absolutely necessary. I am finding that I end up using make_curve in many of these nodes.

    If you could release a new version of NodeBox with a simple make_curve node, as you said you wanted to do back in November of 2017, would be a solid step forward.

    (FYI - the other custom node I am forced to use from time to time is contours, a very simple node you wrote which just turns a path into separate contours. I think that is also worthy of promotion to a full-fledged node, though the need for make_curve is more urgent.)

  8. Support Staff 8 Posted by john on 10 Jul, 2019 09:47 PM

    john's Avatar

    UPDATE

    I just made a minor revision to my make_curve node. Same functionality; all I did was change the order of the ports. NEW VERSION ATTACHED.

    As I learn more about bezier curves I notice that the rest of the world always lists the four points of a bezier curve in P1 C1 C2 P2 order (with the control points in the middle and the end point last). It was confusing having my ports in a different order, so I changed my order to match.

    This did require a change to the python code as well. Going forward I will be using this new node which requires the revised make_curve.py file. This is what I will be using in my soon to be released node library.

    The new version is in the attached zip file. The demo also includes an updated version of fit_curve. I recommend using these new versions of make_curve and fit_curve (with the new make_curve.py) in any new projects you make.

    Frederick, if you're still out there somewhere, this is the version I wish you would add as a first class Nodebox node. Many of the new nodes I will soon be releasing depend on this one custom node.

    John

  9. Support Staff 9 Posted by Frederik De Ble... on 12 Jul, 2019 03:13 PM

    Frederik De Bleser's Avatar

    Hi John,

    Finally I found some time to look at some of the forum posts. My job has changed somewhat in the last year and going forward, I will have even less time to work on NodeBox. It's not part of my job description; personally I'm also in the process of building a house so I have very different engagements at the moment.

    I don't think it's realistic to build entirely new functionality in NodeBox 3 for now. The curve node seems easy enough, and something I will consider soon.

  10. Support Staff 10 Posted by john on 12 Jul, 2019 10:39 PM

    john's Avatar

    Hi Frederik,

    Thanks for letting us know. If you can find the time to publish one minor point release (maybe the last we will see for a very long time) please consider adding two other pieces of low-hanging fruit:

    In priority order:

    1. make_curve node

    2. contours node (my second most commonly used custom node, often used with make_curve. I am attaching the one-line python code you wrote for easy reference.)

    3. a fix for the option-drag bug (http://support.nodebox.net/discussions/nodebox-2-3/6122-option-drag...)

    I can think of a few other quick improvements / bug fixes that would make a big difference without requiring entirely new functionality (e.g. publish as list/value http://support.nodebox.net/discussions/general-discussion/14887-fea...). I am also about to release a node library with over fifty nodes; a few of these are quite simple and might be worthy additions to the core. Let me know if you want any more ideas.

    I can only imagine how busy you are with your house (congratulations) and your new teaching job. If you can give us one last point release before you go the entire community would greatly appreciate it.

    John

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • Curves!.zip 8.86 KB
  • Curve_Samples.png 51.7 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

24 Aug, 2019 03:14 AM
11 Aug, 2019 01:17 PM
08 Aug, 2019 04:13 AM
02 Aug, 2019 09:27 PM
18 Jul, 2019 10:05 AM

 

12 Jul, 2019 10:39 PM
08 Jul, 2019 12:47 AM
06 Jul, 2019 02:12 AM
29 Jun, 2019 10:13 PM
29 Jun, 2019 10:17 AM
26 Jun, 2019 08:54 AM