NCalc and Dynamo's Formula node

You WILL love the formula node in Dynamo.  Resistance is useless.

The Formula node is a beautiful thing.  Once you get the hang of how it works, it will replace a number of other nodes.  Lots of folks think that you use it for doing fancy calculations with fancy names like "logarithm" or "law curve", but it's got all sorts of other banal uses.  Driving the Formula node's excellent operations is NCalc, "a mathematical expressions evaluator in .NET. NCalc can parse any expression and evaluate the result, including static or dynamic parameters and custom functions".  The full description of the project can be found here.

As a non-text based programmer, the Formula node is my gateway drug to "real programming" (oooh, scary) because it's like dipping your toes in the deep and churning waters of traditional coding without having to plunge in up to your naughty bits.

For instance, let's say you were going to add 3 numbers, 1+2+3.  You COULD do this with the big friendly looking Add nodes:

But, my goodness that looks clumsy.  How about this instead?

Ah, much tidier, and the math syntax is recognizable to any 2nd grader.

OK, something a little more involved.

Or stuff that isn't necessarily an equation, like an IF/THEN statement that makes sure an output does not fall below a threshold:

Here the formula node is not only more legible, it actually becomes more powerful than the dedicated nodes, because it can handle lists of numbers much more easily.
(for more on how that sequence of numbers is made, go here)

Once you get into the logic and syntax (and visit the NCalc site to understand all the built in functions) you can go hog-wild.

(You know, "hog-wild" in the way that only someone sitting alone at a computer talking about math on a Sunday night with a shot of bourbon can . . .)

Examples of some other things you can do with the formula node can be found here:
- Page 28 of Dynamo Visual Programming for Design
and here
and most importantly, http://ncalc.codeplex.com/

You WILL love the formula node in Dynamo.  Resistance is useless.

No comments:

Post a Comment