Grasshopper

algorithmic modeling for Rhino

Hi everyone,

I'm trying to understand one part of grasshopper that's been on my mind for a while but only just had a real need for it.

This is my problem:
Divide a curved line into segments of a specified length r (point to point, not along curve) and generate a set of points. The final unused part of the curve can be ignored.

My solution attempt:
- Generate the curve
- Identify the beginning point
- Draw a circle of radius r at this point
- Find the intersection point between the circle and the curve

(this is where it is getting more difficult)
- draw another circle r at this point
- find the intersection point between the second circle and the curve
- draw another circle r at this point...

...- circle does not intersect with curve.

In my mind, this is a relatively straightforward procedure consisting of a type of if -> then loop with a check. I could create the procedure in grasshopper by copying and pasting the code lots of time and having a long linear process but I feel that there should be a more compact solution.

Does grasshopper allow for this sort of operation or will I have to take my visual basic/c++ book down from the shelf again?

Thanks,
Zygnoth

ps I have a basic grasshopper script written but I think it's explained adequately above. If you want me to post just let me know...

Views: 493

Replies to This Discussion

Hi Zygnoth,

Is the distance between points along the curve the same?, if so the DivideByDistance component should fo the trick!

Cheers!

Evert
Thanks Evert, that does the trick alright!

But as a technique, is there another way of doing it - where you feed one end of a script back into the first part again? By using the same operator but feeding its own output back into its input?

I realise that this could lead to scripts diverging but can it work as a process for grasshopper or is this offbounds?
Attachments:
Evert is right.

And also if your curves are non-planar the routine would be distances based on sphere/curve intersection points.

Hence the [Divide Distance] icon...

Thanks Taz,

I guess the question wasn't so much about the correct routine to use (which I obviously didn't know about but great to know now!) but about whether grasshopper can feed into itself...
Recursion can only be done with a scripted component. So you would have to use VB.NET/C# and pick up some RhinoCommon.

Andrew Heumann was playing around with recursive-like operations so you could check this out:

http://heumanndesigntech.wordpress.com/2010/08/13/iteration-in-gras...
Hi taz,

Thanks for the link looks very interesting, I'll check it out. I've been doing some research on closed form sequences to try to generate recursion based on simple functions and no scripts. I'll post something when I get results.

Cheers

Evert
This is part of the reason why we have boon looking forward to clusters for some time. With a centralized definition that can update all instances, clusters offer us a way to not only perform a limited level of recursion, but also to keep the canvas space organized and (relatively) easy to follow at the same time. Even with clusters though you are limited to knowing ahead of time how many times you will loop the function back on itself. You can currently only do true looping in script.
Have you managed to create some looping in the scripting?

I've tried but I can't stop the VB script from taking all the inputs at the same time instead of constantly updating them. I'm probably not well read enough in VB to know if I'm doing this wrong...
If you set the Input type on the component to list, you can then iterate through the list using a For loop. Something like this ...

RunScript(ByVal L1 As List(Of Object), ByVal A As String, ByRef L2 As Object)
Dim strTest As String
Dim listL2 As New List(Of Object)

For i As Integer = 0 to L1.Count - 1
If L1(i).To_String = strTest Then
listL2.Add(L1(i))
End If
Next i
L2 = listL2
End Sub



This component would iterate through each element in the input list and add it to the output only if it's ToString matches the input of A. This means no Null values for unmatched data branches.

Remember that all components have an inherent limited version of 'For Each' in that it will perform the function of the component upon each data branch passed to it. Most of the time you don't need to replace this For loop unless you want to selectively or corporately process the data.

Hope this helps!

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