How to create Differential Functions?

Hi everyone!

I have been searching for a while but couldn’t find a solid way to create differential functions in grasshopper, such as the image that I shared. Does anyone have any idea?

thanks in advance!

attractors

Hi,

Check these plugins which have the Chua attractor possibility

Some examples found here from here :

http://www.valis.io/fracturehopper.html

Cheers,
BVR

You can do this iteratively using Anemone or Hoopsnake because those equations are telling you how the position changes with respect to time, so in iteration 1 you use the initial position and in iteration 2 you use the position from iteration 1, and so you update iteratively, and the positions in each iteration form the path.

Another option is that you evaluate the function in one position and in another position infinitesimally close (as far as 0.001) and the position difference and divide it by the magnitude of the distance (pt(x) - pt(x+dx)) / dx, and this also gives you how the position changes with respect to time. So at each position you can evaluate how it should change using that equations and update it iteratively.

GH has no direct support for the funny equations, but by applying math aprox. you can do it anyway.

1 Like

You can also do this kind of thing without plugins using a very short script.
Like this:

      for(int i = 0;i < substeps;i++)
      {
        double x,y,z;
        x = p.X;y = p.Y;z = p.Z;
        double g = e * x + (d + e) * (Math.Abs(x + 1) - Math.Abs(x - 1));
        p += t * (new Vector3d(a * (y - x - g), b * (x - y + z), -c * y));
      }

chua.gh (6.9 KB)
8 Likes

Hi @DanielPiker ,

Is it possible to do the same thing with Expression ? in GH without coding. Just curious to know about it.

Hi @ajarindia,
No I don’t think it would be possible to do this with the Expression component, because it has to be calculated iteratively.
The values at each step are calculated based on the values in the step before, and there is no way to directly calculate the nth step without also calculating all the preceding steps.

1 Like

Hi @DanielPiker,
is there going to be any implementation in terms of a recursive solver in GH2?
Thank you

That’s one for @DavidRutten

Thank you,

Since I have no experience scripting in C#, I just copied and pasted your script and modified it into another attractor(halvorsen attractor) for understanding the logic but the result is not quite well.

Here is the modified version of the script:

for(int i = 0;i < substeps;i++)
{
double x,y,z;
x = p.X;y = p.Y;z = p.Z;
p += t * (new Vector3d(-a * x - (4 * y) - (4 * z) - (y * y), -a * y - (4 * z) - (4 * x) - (z * z), -a * z - (4 * x) - (4 * y) - (x * x)));
}

The halvorsen attractor.gh (5.9 KB)

Looks like you just need to change that initial position

    if(reset)p = new Point3d(1, 0, 0);
    else
    {
      for(int i = 0;i < substeps;i++)
      {

It looks like your image comes from this site:


where they say they relied on this site, which has scripts for all of them:
http://www.3d-meier.de/tut19/Seite300.html

It looks like the code is in German, and it’s in some C4D script language but you should still be able to extract the math part and translate it into C#

1 Like

Also - here’s a little update of the script - so instead of using the data recorder component, it stores the point list itself, and adds several at a time, which is much quicker:
halvorsen_attractor.gh (6.9 KB)

2 Likes

Oh, thanks for the correction.

Yes I have found them from the website that you have shared and I thought it is very interesting te create those mathematical expressions in gh. But I didn’t relaize that the codes have already been shared. Also thank you for that!

that looks much better, I think I need to learn the logic of scripting asap. It might be a dumb question but should I start with C# or Python?

Both are good, people just have different preferences.
I wouldn’t stress too much at the beginning about which one is better, just find some tutorials or examples you like the look of and start trying it out.


So you don’t feel limited by coding to play with this. You can use the fast version of Anemone if you are only interested in the final result.
ChuaAttractorExpressionsAnemone.gh (16.3 KB)

newPosition = currentPosition + HowPositionChanges(currentPosition)
2 Likes