Grasshopper

algorithmic modeling for Rhino

Hello.

I would like to make a C# component in Rhino, with following C# code:

#include<stdio.h>
#include<math.h>

void main(){
 double f0;
 double n21,n22,f;
 double A=0.373;
 printf("# f0, f, n21,n22\n");
 for(f0=1.0e-10;f0<=0.1;f0=f0*pow(10.0,0.02)){
  n21=-2.0+floor(1.29*pow(f0,-0.25));
  n22=-2.0+floor(A*pow(f0,-0.25)*(12.0)*sqrt((n21+2.0)/(11.0*n21+43.0)));
  f=(27.0/2.0)*f0*pow(n21+2.0,-2.0)*pow(n22+2.0,-2.0);
  printf("%g %g %i %i\n",f0,f,(int)n21,(int)n22);
 }
}

Any help with this please?

I am beginner with both C# and creation of C# components in Grasshopper.

I attached the .c file with the same above code.

Thank you.

Views: 3095

Attachments:

Replies to This Discussion

So now it should look like this:

    double f0;
    double n21, n22, f;

    double A = 0.373;
    int index;

    for (f0 = 1.0e-10, index = 1; f0 <= 0.1; f0 = f0 * Math.Pow(10.0, 0.02), index++)

      output = output + index.ToString() + " " + f0.ToString() + " " + f.ToString() + " " + ((int) n21).ToString() + " " + ((int) n22).ToString() + "\n";
    {
      n21 = -2.0 + Math.Floor(1.29 * Math.Pow(f0, -0.25));
      n22 = -2.0 + Math.Floor(A * Math.Pow(f0, -0.25) * (12.0) * Math.Sqrt((n21 + 2.0) / (11.0 * n21 + 43.0)));
      f = (27.0 / 2.0) * f0 * Math.Pow(n21 + 2.0, -2.0) * Math.Pow(n22 + 2.0, -2.0);

      output = output + f0.ToString() + " " + f.ToString() + " " + ((int) n21).ToString() + " " + ((int) n22).ToString() + "\n";
    }

?

Not quite:

double f0;
double n21, n22, f;
double A = 0.373;

output = "# f0, f, n21, n22 \n";

int index;
for (f0 = 1.0e-10, index = 0; f0 <= 0.1; f0 = f0 * Math.Pow(10.0, 0.02), index++)
{
n21 = -2.0 + Math.Floor(1.29 * Math.Pow(f0, -0.25));
n22 = -2.0 + Math.Floor(A * Math.Pow(f0, -0.25) * (12.0) * Math.Sqrt((n21 + 2.0) / (11.0 * n21 + 43.0)));
f = (27.0 / 2.0) * f0 * Math.Pow(n21 + 2.0, -2.0) * Math.Pow(n22 + 2.0, -2.0);

output = output + index.ToString() + " " + f0.ToString() + " " + f.ToString() + " " + ((int) n21).ToString() + " " + ((int) n22).ToString() + "\n";
}

Hi I am a beginner and I can't find this anywhere on google (I don't think I am searching this correctly.

When I place a C# script in grasshopper, it already has the variable names set eg.,

private void RunScript (object x, object y, ref Object A)

I want to change it so that my x input can be a bool and my y input can be a string

any suggestions?

Oh cool, I did not know that floor was a method. Thanks :)

EDIT: Oops, this was supposed to come under Giulio's comment. 

Thank you !!! :)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service