Using ChatGPT to translate Math into Python

Want to explore an intersection of how AI and Dynamo can work together, right now? Then take a walk down history lane with me as we endeavor to build some yarn in Dynamo…

First, let’s find something fun, like yarn math! :heavy_division_sign:

And then find the part of the Research Paper that has the formula required to generate geometry :mirror_ball:

Now that we have some epic math, lets use ChatGPT to generate the Python code required to actually use that math in the context of Dynamo :heavy_plus_sign: :heavy_division_sign: :heavy_equals_sign:

Trying to paste this into the Dynamo Python Node won’t quite work, as the Python node in Dynamo has some specific things we must attend to, such as how to get data into the node and also how to get it out again. So, we ask ChatGPT to retune the code to match this! (Not so) strangely, it changes the result significantly, removing the definition entirely.

But we can just ask it to add it back in again :slight_smile:

Now we are left with some code we can try running… let’s give it a whirl! We need to know a tiny bit about the Dynamo Python node editor here… namely where to paste this code (Hint: There are textual hints in the boilerplate!) and to delete the additional OUT variable… (Or it overrides the ChatGPT one if it comes later). And boom :boom: we have a result! A series of numbers… not quite there yet.

So what if we try feeding it a list of numbers for the t variable rather than a single one? :question: Whoops… failure. Back to ChatGPT!

So we ask ChatGPT to make our t values able to be a list, and it provides :trophy:

Replacing our code in Dynamo and running the graph returns… lists of three-number sets! Coolio :sunglasses: Closer to getting towards points as these numbers now represent our X, Y and Z values. Onwards to points! :point_right:

Now this is where it get’s a little funky… as ChatGPT may not get you further. Two attempts got it changing the code structure, but not actually returning points as requested… but it got us pretty far! From this point on you can use your epic Dynamo knowledge to take it home :houses:

So we transpose the list to switch our columns and rows, going from a list of sub-lists containing three elements a piece (Representing an X, Y and Z set), to three sublists containing all of the X, Y and Z numbers.

We then use some DesignScript as short-hand to pull out those sublists into their own outputs, one each for the X, Y and Z lists.

Then we generate points from those number lists and run a NurbsCurve through them and voila… yarn! Oh wait… not quite yet :thinking: Hrm

So the math is there, but the numerical values for our Python code have the t value as our input lists (Good) and a set of hardcoded values for the "a" (asine(2t), "h" (hcost(t) and "d" (dcos(2t) coefficients. This is what we can tweak next! So let’s ask ChatGPT. :speaking_head:

So let’s paste this into Dynamo and see where we get to. With a little effort going into setting up the lists of numbers in the first place… we have a yarn curve!

And it’s not too hard to see how you can take that further using some basic translation to make it… more Yarn-y :thread:

So come have a play with the graph :playground_slide: :smiley:

Dynamo_Yarn_Math.dyn (49.3 KB)


Now I can use Dynamo to knit my own sweater. :snowman_with_snow: :cloud_with_snow:


Pics, or it didn’t happen! :sweat_smile:

1 Like