algorithmic modeling for Rhino

Recently i have started to re-script the code, i originally wrote in java, into grasshopper and i am having trouble on how to create arrays in there a specific command in grasshopper for array or using VB and C#??


i have attached the part of java code that i am trying to re-script...its very simple, if there is a way of creating a string of array in grasshopper...


Views: 20382

Replies to This Discussion

Hi David,


I tried using planer and divide surface to make a plane using the 4 corner points (with some help from Pieter) , But i wasn't able to convert that plane into a grid, is it possible to convert it to a grid, or a Grid to generate from 4 point as a plane??


Hope to hear from you soon...


How do you define a "grid" exactly? Is it a single list of point coordinates? Is it several columns of point coordinates? Is it a collection of closed polylines? Is it a collection  of columns of closed polylines? etc. etc.


You can approach this problem in two basic ways. The first is to generate an orthogonal grid using the Square or Rectangular Grid components, then deform it to fit your outline. The second approach is to start with the deformed outline and generate an already deformed grid.


Pieter used the latter approach in the other thread which I'd say was the smart thing to do. Using an existing surface UV space gives you a large amount of intuitive control over how your grid behaves.


I attached a file which uses the latter approach; it deforms a grid from World Space to Surface UV Space.



David Rutten

Poprad, Slovakia


"How do you define a grid?"


The type of grid I required for my definition was a collection of closed poly lines ( actually it was for the same 2D array definition), the one you provided is working with it... Thanks man...


I have three questions regarding generating the grid from an outline.

  • Can we create an outline with more than four points?
  • Can we introduce a point in the middle of the grid, to scale up/down boxes within a certain range or radius from the point (like the one where you change the radius of the circles in a grid using distance from a point), if yes How?
  • If we have generated a surface from curves using loft, it is mapping the grid to it, but not showing the array output, why (files attached)?
Again, thanks alot David, really appreciate your effort...

"Can we create an outline with more than four points?"


Yes, this is theoretically possible. But when you have more than 4 edges, you also need to supply more information about how the grid-cells are distributed as this can now no longer be inferred from the outline. If you have 5 corners for example, there are 5 possible ways to fit a rectangular grid. Here are three:



You have to figure out how to define which of the possible distributions you're after and then you can start looking for a way to implement that in Grasshopper.



David Rutten

Poprad, Slovakia

So basically introducing a bisector of any one of the angles, and splitting it into two 4point surfaces,right?


And the other two ( introduction of point and surface from loft), are they possible ?



Well that's one way, the other approach would be to ignore one of the corners, create a regular 4-edge grid, then deform it into the missing corner.


I've broken the build and cannot open any ghx files until I fix several hundred compiler errors, it will be a while before I can do anything practical.



David Rutten

Poprad, Slovakia

OK, no problem, i'll wait for the other two...


How would i deform the grid after its been generated with 4 points??

I've been thinking about this and I decided to write a small function for RhinoCommon that is essentially the inverse of ClosestMeshPoint().


ClosestMeshPoint() is a function that find the point on the mesh closest to a 3D point. But it provides a lot of additional information such as face-index and barycentric coordinates and such.


I made a function that evaluates a Mesh at a given meshpoint. This basically allows you to 'remap' points from Mesh A to Mesh B, provided they have the same topology. This is synonymous with mapping points from Surface A to Surface B via UV domains.


In the image below you can see how a bunch of points tracing the letter R are transferred from a flat mesh to a 3D mesh.


Of course this won't help you at this instant, but it might be a useful tool to deform geometry in a controlled fashion.



David Rutten

Poprad, Slovakia

"Can we introduce a point in the middle of the grid, to scale up/down boxes within a certain range or radius from the point (like the one where you change the radius of the circles in a grid using distance from a point), if yes How?"


I found a definition, similar to what i was asking in the above question, but the output is a pline, is there a way to use that as a grid (closed polyline) for my array definition?


I have attached the definition, along with mine (where i intend to use it)...

Interesting thread


I was attempting to replicate the function you wrote for converting an array into a datatree by nested for loops:

Function Array2Tree(Of T)(ByVal arr(,) As T) As DataTree(Of T)
'Declare a new DataTree
Dim tree As New DataTree(Of T)

'Iterate over the first dimension of the array
For i As Int32 = 0 To arr.GetUpperBound(0)
'Iterate over the second dimension of the array
For j As Int32 = 0 To arr.GetUpperBound(1)
'Insert the current value into the DataTree.
'The first dimension ends up as the Path,
'the second dimension ends up as the index.
tree.Insert(arr(i, j), New GH_Path(i), j)

Return tree
End Function

I am using GH_Structure (because I'm making a custom component) instead of DataTree using the generic type <T>, but it gives me the following error in Visual Studio:

"The type 'T' cannot be used as type parameter 'T' in the generic type or method 'Grasshopper.Kernel.Data.GH_Structure<T>'.  There is no boxing or type conversion from 'T' to 'Grasshopper.Kernel.Types.IGH_Goo'."

It seems to work the other way round, if I create a function that reads a GH_Structure and creates a corresponding 2d array:

public T[][] convertStructureToArray<T>(GH_Structure<T> inStructure) 

Is there anything I can do to get around this?  It would make it a great deal easier not to have to make a new function for each type of GH variable that the function could possible have to process...






  • Add Photos
  • View All


  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service