Grasshopper

algorithmic modeling for Rhino

Hi all!

I'm relatively new with Grasshopper and C#, so I hope some of you can help me out.

My C# block has three inputs, two lists and a value.

I want to create some sort of a graph out of the two lists.

One list contains all the x- values, and the other list contains the corresponding y- values.

So for (x=1.0, y=2.0) (x=2.0, y=5.0) ..... (see picture)

My desired output would be a y- value for the input x- value of 5.6.

I tried to find it on internet, but could not find the correct statements.

Is there a way to simply write this in code?

I've added the file and the picture to make it more clear.

Wim

Views: 749

Attachments:

Replies to This Discussion

This graph would make it more clear I think.

Attachments:

See attached and see if it is what you want!

Attachments:

I want to have it in C# code.

But that's indeed a solution tackle the problem.

Thanks!

[Interpolate Data] component is enough for you? See attached.

Attachments:

I want to have it in C# code, but thanks anyway

private void RunScript(List<double> D, double ts, ref object A)
{

Interpolator interpolator = new Interpolator(D.ToArray());
List<double> list = new List<double>();
foreach (double t in ts) {
double val = interpolator.InterpolateLinear(t * (D.Count - 1));
list.Add(val);
}

A = list;
}

private void RunScript(List<double> D, double t, ref object A)
{

A = new Interpolator(D.ToArray()).InterpolateLinear(t * (D.Count - 1));

}

Hoi Wim,
here's my two cents, maybe you can translate it to C#

Thanks, but I was looking for all of this in C# code indeed.

I think rewriting this in C# will work.

Since I posted the discussion, I found another way of approaching the problem.

So I start combining them.

Hey Wim, 

here is the file. May I ask why do you need this in C# if the code does exactly the same as the Construct Point component? The construct point component when it has 2 lists as input in X and Y it will create points by matching each index of each list in order. For example index[0] of list X with index[0] of list Y , etc...

If the lists are are of uneven length the component will match the last index of the shortest list with the remaining indices of the longest list. For example list X has 10 items and list Y has 12 items. The matching logic would be list X [9] list Y [10] and list X [9] list Y [11]

Cheers

Nicholas

Attachments:

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