Grasshopper

algorithmic modeling for Rhino

Identifying numbers in a list relative to previous numbers in the list

I'm having trouble with a definition I'm working on. I'll do my best to describe it clearly.

I have a list of numbers, and I want to identify items in the list which follow specific rules. I assume I will need to script it, but I'm relatively new to the scripting scene and syntax is still a fairly big issue. So if someone can see a way to do this without scripting that would be cool (I'd like to avoid using hoopsnake for it though). This is the idea:

Let X1 be a number in a list of numbers.

If X1 is negative find the next value that is 180 larger or 360 smaller (whichever comes first) and return it's item index

Else If X1 is positive find the next value that is 180 smaller or 360 larger (whichever comes first) and return it's item index

Once the new value is found, store it as X2 and test the remaining  numbers against  it (the next value based on X2 would be X3, then X4, etc... The naming convention isn't important, it can be whatever).

Repeat until the end of the list is reached. 

So basically I'm just looking for the item indexes of the values of all X's. Any advice would be hugely appreciated. 

-Brian

Views: 1320

Replies to This Discussion

Thanks, I forgot to comment that out.

I also figured out another big problem:

if (item >= limit + && limit != 0)
{
limit = limit + SN;
flag = true;
}

should have been:

if (item >= limit + SN && limit != 0)
{
limit = limit + SN;
flag = true;
}

That was causing a lot of confusion.

Thanks so much for all your help,

-Brian

I'd be interested to know if this Native GH approach works for you.

Attachments:

Hey Danny, thanks for your reply.

Im a little confused about what I'm looking at, but that's just because I haven't sifted through it all yet :)

I do notice something that stands out though. Looking at your original list of numbers, if I am to go through and check manually to see what I should be getting out, I think you should only get a few outputs (which is why I was confused by all the outputs at the end of the definition.

For example, just as an example I started with X1 as 279 (item index 11). When I did the math, the only indexes that I got were 15,28, and 33.

This is because:

since 279 is positive, look for next number that is at least 180 less or 360 more than X1.

the value of 78 (item index 15) is the first value to satisfy this requirement.

Then, since 78 is smaller than 279, we are looking for the next value at least 180 more or 360 less than 78.

The value 272 (item index 28) is that next value.

Then since 272 is larger than 78, we are looking for the next value at least 180 less or 360 more than 272.

The value 52 (item index 33) is the next value.

So the definition should output the following:

indexes 15, 28, 33.

Does that make sense?

I took x2 to 180 less and x3 to be 360 more.

Also it applies to every item in the list, hence so many outputs. Obviously this doesn't work towards the end. I just wondered if it would work when you plugged you list in.

I guess not.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service