Drainage Direction Script

I made a python script that estimates the direction of drainage paths on a surface.

It does not deal with puddling or accumulation, and if you have any suggestions on how to make it faster or to improve it in any way, let me know -- this is a first draft.

 

you can see the python code in this github gist:

https://gist.github.com/1054969

 

 

 

Load Previous Replies
  • up

    Vicente Soler

    I'm probably too late but i just read the last replies.

    The VB code to make this work with a mesh object would be something like this:

     

    Private Sub RunScript(ByVal pto As Point3d, ByVal m As Mesh, ByVal tol As Double, ByVal maxsteps As Integer, ByRef A As Object)

     Dim ptl As New list(Of point3d)
     Dim pl As New plane(pto, vector3d.ZAxis)

     While ptl.count < maxsteps
       Dim mpt As meshpoint = m.ClosestMeshPoint(pl.origin, Double.MaxValue)
       pl = New plane(mpt.Point, m.NormalAt(mpt))
      If ptl.count > 0 AndAlso pl.OriginZ > ptl(ptl.count - 1).z Then Exit While
      ptl.add(pl.Origin)
       Dim an As Double = vector3d.VectorAngle(pl.XAxis, -vector3d.ZAxis, pl)
       pl.Rotate(an, pl.ZAxis)
       pl.Translate(pl.XAxis * tol)
     End While

     a = ptl
    End Sub

     

    Note that since mesh welding affects the mesh normals it will also affect the drainage direction.

    6
  • up

    Chris Ingram

    hi all,

    is anyone able to elaborate on the method to achieve this with a mesh. I am a novice when it comes to writing code directly and cant seem to work out how Vicente's code is applied to achieve the results seen at the end of the thread. I have tried copying them into a VB script component but must be missing something. Is anyone able to post a definition that makes Benjamin's original drainage script work for a mesh terrain?

    Many thanks

    chris

    7
  • up

    Juli Bent

    Hello everyone,

    I am a total beginner with Python, Rhino and Grasshopper, but I need to model the drainage paths on a surface.

    I imported a .jpg file into grasshopper and created a Surface from Points. Now I tried to use your python script to model the drainage. 

    When running the script it appears the Runtime error 'terrain surface' is not defined. 

    But to be honest I am not sure if I even did connect the Python component correctly with my surface and further on then imported the surface correctly into the skript. 

    As I said, I am a total beginner and I would really appreciate any help.