Grasshopper

algorithmic modeling for Rhino

hello guys,
I have a problem with a datatree..
I need to choose in every path that item, which has the most simular value to the item which was chosen in the preceding path.
So every selecting operation in any path has to compare seperately with the result of the preceding operation, which needs a loop.
and.. this operation should work several times within one data-tree.. (so the operation should start several times with a new starting-value, which means a second loop)
(this problem emerges because I need to select the right sectionpoints of several curves with a bunch of lines)
 
((((I already solved this problem by a plan-B, with a hoopsnake element.
But VB would be a much more precise and clean solution.))))
 
So I was trying to fix this problem with visual basic.

Here is my code with an error I cannot deal with, please help me..:

Private Sub RunScript(ByVal all_lengths As DataTree(Of Double), ByVal StartingCount As Integer, ByVal StartingPaths As List(Of Integer), ByRef sel_lengths As Object)


    Dim i, j, k As New Integer

    Dim min_lengths As New datatree(Of Double)

    Dim ItemCount As New Integer



    For i = 0 To StartingCount - 1
      'here I´m defining the start-values which should be the smallest value in every start-paths. every first iteration in the j-loop needs this value in the first place.

      Dim arrLenBranch As Double() = all_lengths.Branch(StartingPaths(i)).ToArray()

      Array.Sort(arrLenBranch)

      min_lengths.add(arrLenBranch(0), all_lengths.Paths(StartingPaths(i)))

      'the j-loop is running all paths between the Start-paths.
      '..and it is starting with "(i)+1" because the first value was already defined in i-loop.
      For j = (StartingPaths(i) + 1) To StartingPaths(i + 1) - 1

        arrLenBranch = all_lengths.Branch(j).ToArray()

        Dim arrLenBranch1 As Double()

        ItemCount = all_lengths.Branch(j).Count

        'in k-loop I calculate how big the difference is between every path-item and the chosen value in the preceding path
        For k = 0 To ItemCount - 1

          '1.Error(BC30455): Für den Parameter "index" von "Public Default Property Item(index As Integer) As T" wurde kein Argument angegeben.(line 117)
          arrLenBranch1(k) = Math.Abs(arrLenBranch(k) - min_lengths.branch(j).item)
        Next

        'Here I sort the difference
        Array.Sort(arrLenBranch1)

        'Here I´m adding the smallest differences to min_lengths
        min_lengths.add(arrLenBranch1(0), all_lengths.Paths(j))



      Next
    Next

    sel_lengths = min_lengths


  End Sub

 
 
 
 
so, if someone has some helping ideas..
Much Thanks!!!

Views: 611

Replies to This Discussion

Could you explain why you are following this logic? What are you trying to do above all?

It looks like a very tangled road.

min_lengths.branch(j).item(k)

tangled?

maybe.

soon I´ll explain it..

meanwhile: "(k)" I don´t need here, because "min_lengths" should stay constant during the k-loop, because I want to compare all "arrLenBranch"-Items by substraction of "min_lengths", which of them is closest to zero. ==> and so I know which of the "arrLenBranch" is closest to "min_lenths".

and, after all, "min_lengths" should represent the chosen value in the iteration before. 

==> and so I want to select in every path of "all_lengths" that Item which is most simular to that one in its preceding "all_lengths"-path. (which doesn't mean just always the smallest value - but the value next to zero after it's substraction with the chosen item in its preceding path.)

the source of this challenge comes up, when you want to get the right section-points after crossing some twisted curves with a bunch of lines. because sometimes the lines are crossing the curves more often than once, and then you get a tree of sectionpoints, in which every path posseses only one section-point is which is the correct one.

why do i want to cross these twisted curves with these lines?

because I´m working on a stair-programm, in which every line represents an edge of one step. and the curves are representing the route of the beam(s) on which the steps are lying.

In my GH program I only want to define the route(s) of the beam(s) by one curve in the 2D-floorplan, crossing the step-lines in the 2D-floorplan. Then the (right selected!!) sectionpoints I can elevate to the precise height of every step. And by lofting a profile at these 3D-points I get (a) beam(s) which progresses the same way, as the stairs are doing - as twisted as they might be. If you know an easier, less tangled solution for that, you`re welcome.. I soon will add some pictures, thank you for your interest!!

this is the situation in the floorplan..

the yellow marked curves should represent the routes of the beams,

the bunch of red lines represent the stairs.

so you can see, that if the stairs become more complex and for example are curling around a center and build a circular staircase, the red step-lines are crossing the beam-curves more than once, and I have to select the right ones. (the right section-point is always the one, with the smallest difference in curve-length to the section-point of the preceding step.) sorry when it gets too complicated, maybe my explanations are much more complex than the principle behind, but I can´t do it better.

this shows the result, when wrong section-points are selected

..and this shows the right solution.. (but point-selection works here with an hoopsnake element, which is only my plan B, because it´s much to slow..)

in the attatched file upside you can see the hoopsnake-element, and the logic it follows.

I can also share the whole stair-case-file if wished, but it´s so complicated, I don´t think it will get us closer to a solution of this curve-length-selection-problem.

SIMPLE EXPLANATION:

as picture it´s easy to understand -

to finish my stair-program I´m searching for a VB code that accomplishes this kind of selection:

in every path there is only one item which is correct:

- the right value in the 0. path {0;77} is the smallest one.

- right value in the 1. path {0;78} is the value which is closest to the chosen value in the preceding path

- ..and so on for {0;79} and {0;80}

but when the paths change their first level, the iteration should start from the beginning:

- right value in the 4. path {1;32} is the smallest one.

- right value in the 5. path {1;33} is the closest to the chosen one in {1;32}.

- right value in the 5. path {1;34} is the closest to the chosen one in {1;33}.

..to be continued.

..this is, what I want to achive in the VB code, I implemented at the beginning of the discussion.

..and this is how I designed the input-parameter of the VB-element:

 if someone could help me .. super-great!

Attachments:

First script doesn't take the path indices into account, I post it here merely because the algorithm is easier to understand. The *VB2.gh file does I think what you are after.

Attachments:

wow. thats just a beautiful code.

and it explains much of VB for me.

thank you david!

it is saving me a lot of time..

david, sorry, but there seems to be a problem left, when it comes to bigger datatrees than the posted one above.

for example: the path {0;102} jumps to 57.8 but it should select 77.0, so also the following values are wrong. I hope I didnt miss something...but I doublechecked with both of your solutions.. see attached file, if you have time left.

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