Grasshopper

algorithmic modeling for Rhino

Hi All,

Im trying to write a VB.net component which would get as input some geometry, evaluate its centroid and then create copies of this geometry matching the centroid with the points of a 3d array I previously created and stored as a Datatree.

What classes/method should I use ?

Any help ?

Jason

Views: 4039

Replies to This Discussion

Assuming its a brep, declare a variable with the type OnMassProperties to pass into OnBrep.AreaMassProperties. Then use the Centroid method of your declared variable to get the point and move accordingly.

If its a curve, you'll still have to call AreaMassProperties, but the structure of the arguments are going to be a bit different. You can even get away with retrieving the point directly through that method.
to follow that up, you subsequently need to create vectors from this centroid to all your target points, and use the vectors as transformation. Depending on the geometry type you are using, some have a built in function .Transform, or you could use OnXForm.
short hand method...

myBrep.Translate (ToPoint - FromPoint)
Hi Damien and Suryansh ,

Unfortunately my geometry is not a closed brep, does it work anyway? Please look at the picture


Anyway I am confused about how to use the AreaMassProperties method. I read the rhino sdk .net help but it not clear though.

Let's say I have as input from GH my geometry and grid points (geo as Onbrep, pts As List (of On3dpoint) )

I declare the following
Dim cent As OnMassProperties
Dim ptCent As On3dPoint = cent.Centroid

But then how do I pass ptCent to my geometry through AreaMassProperties?
See if the attached helps. All you need to do with the AreaMassProperties method is pass in the OnMassProperties variable that you've declared. Only after you've done that can you extract the centroid of the object. Then the centroid is just like another point.

It also doesn't matter if the object is closed or not
Attachments:
Damien,
thank you very much! this is extremely helpful . I actually didn't know I could make copy of my geometry by simply defining a new object and pass by it the constructor of the class (Dim tempBrep As New OnBrep(brep) ).

The trouble I have is that my brep it is not close (ie it's made up of non connecting surfaces) so it seems it calculates centroid for each surface and not for the whole piece.

How would be convenient to input this kind of geometry? Input as geometry object and then calculate bounding box? But I feel it still will calculate bbox for each surface !
In this case, making the copy is very important. The translate and transform methods will work directly on the object that's calling the method, so without creating the new instances you'd just be moving the same one around.

Multiple breps and open breps are two different things. Open breps will still calculate a centroid, but it just makes less "technical" sense. If you want to find the "centroid" of multiple breps, then you've got 2 options. The first is to take the centroid of each one, then average them all out. The second is to get the collective bounding box of the breps and then use the middle of that. My recommendation is to go with the first option as that's much easier and faster than the second. With the second option, you really want to get the tight bounding box to deal better with trimmed objects, which is a slow process. Even though your objects look fairly regular, some odd shapes could have the center of the bound box be pretty unrepresentative of the point your after.

Here's a little code for the first solution...

'''add all centroids together
Dim avgCentroid as New On3dPoint
For i as integer = 0 to BrepList.count -1
BrepList(i).AreaMassProperties(massProps)
avgCentroid += massProps.centroid
Next

avgCentroid /= brepList.Count '''average the summed point out...
'''Now move each of the breps from this point to the target points...
Hi Damien,

thank you very much for helping! I have to say after your explanation the uses of such classes is much clearer and helped to make some improvements in the code. It's shame rhino.net documentation is a bit poor at moment.

In order to make copy of geometry as it is stored in a list now I used a for each loop to pass single breps.

For Each j As OnBrep In BrepList
Dim tempBrep As New OnBrep(j)
Next


I am quite happy with the result except the calculation speed which decreases steeply if you keep increasing the 3d points array number (especially after 10 points in x,y,z dir).

Is probably due to how the geometry is built? that is single breps instead of a single brep? This is actually another issue as I am not able to join my geometry within GH (the brep attached is made with a loft component from 2 scaled cubes - one inside the other).

Thanks for helping!
Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service