Grasshopper

algorithmic modeling for Rhino

I am newbie in C#.  I made GH definition for sphere point creation - it's works perfect ,and trying  to make same C# component - it  not works at all. Can somebody help me with it ? Problems with formula that generates "fresult" list (line: f = Math.Acos(-1 + (2 * loop - 1) / x) ). Thanks for help. 

double f,t,k,g,b;


List<Point3d> pts = new List<Point3d>();
List<double> fresult = new List<double>();


for(int loop = 1;loop <= x;loop++){

f = Math.Acos(-1 + (2 * loop - 1) / x);
t = Math.Sqrt(x * Math.PI) * f;

k = y * Math.Sin(f) * Math.Cos(t);
g = y * Math.Cos(f) * Math.Sin(t);
b = y * Math.Cos(f);
Point3d temp = new Point3d(k, g, b);
pts.Add(temp);
fresult.Add(f);
}


A = pts;
fResult = fresult;

Views: 1146

Attachments:

Replies to This Discussion

In C#, when you divide two integers, you get an integer in return. I.e. this:

-1 + (2 * loop - 1) / x

Is computed in integer accuracy. You should specifically convert one of the division parts into doubles:

-1 + (2 * loop - 1) / (double)x

--

David Rutten

david@mcneel.com

Thank you ,David!!

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service