Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I am currently making a grasshopper definition that requires me to linear interpolate a list. I am able to linear interpolate the list and get the list of outputs. However, I don't know how to reference the list of outputs.

What I wanted to do is that if I choose a number from the range of 1 to 2, I will be able to extract an item from the list. For example, if I choose 1, then the output is -0.5. And if I choose 1.05, I will get -0.49. I tried using list item to extract the data, but that component doesn't allow me to reference the point in that way.  Can anyone give me an advice on how to do this? Thank you in advance for your help. I will appreciate it very much.

Views: 947

Replies to This Discussion

So if I understand correctly, you want to extract a number x using another number t, where x is the same percentage along (-0.5 -> -0.3) as t is along (1.0 -> 2.0)?

Of course not every t will exactly match with any available x in the list of all xs, do you want to find the nearest best solution in that case?

Hi David,

Thank you for the quick reply. Yes, the nearest best solution would be great.

Ok, then you need to map your t parameter to a list index. You can get the parameter for any number using the following expression: f=(t-min)/(max - min), or in your case: f=(t-1)/(2-1), which simplifies to f=t-1. You may want to limit this factor to the (0.0 -> 1.0) range to avoid you getting indices outside of the list. I.e. apply the expression Min(Max(x, 0.0), 1.0).

You then take this factor f and multiply it by the length of the list minus one: i = f * (N-1) to get the index. Of course at this stage the index is still a floating point number, but you can round it to the nearest integer just by running the value through an integer parameter.

Dear David,

Thank you very much for the suggestion. I have tried your way and it works perfectly. I appreciate your help very much.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service