Grasshopper

algorithmic modeling for Rhino

Owkey, this started out as a, for me, simple vb exercise. I have a simple problem. 

2 breps intersecting, I want to know the volume of the intersection. 

 

So I opened the RhinoCommon page and started combining things. This is where it went wrong...

 

So far I got:

 

Private Sub RunScript(ByVal cone As Brep, ByVal centerpoint As Point3d, ByVal points As Point3d, ByVal boundingbox As Brep, ByRef A As Object) 

'move the cone to the point location   

cone.Translate(points - centerpoint)   

' get the intersection   

Dim result As brep() = rhino.Geometry.Brep.CreateBooleanIntersection(cone, boundingbox, 0.001)
'get the volume of the intersection   

Dim volume As Double = rhino.geometry.VolumeMassProperties.Compute(result(0))   

A = volume

End Sub


Both the intersection as the volumeMass give me errors.

 

Any suggestions?

Views: 1973

Replies to This Discussion

Hi Sander,

 

Brep.CreateBooleanIntersection() operates on collections of Breps, not individual breps. I'm assuming you get the following error:

 

error: Unable to cast object of type 'Rhino.Geometry.Brep' to type 'System.Collections.Generic.IEnumerable`1[Rhino.Geometry.Brep]'. (line: 86)

 

This basically translates to: "I wanted a collection of Breps and you've given me a single brep". You'll need to put your cone and boundingbox into a collection. Easiest is to make an inline array:

 

Dim result As Brep() = Brep.CreateBooleanIntersection( _

                                                New Brep() {cone}, _

                                                New Brep() {boundingbox}, _

                                                0.001)

 

I concur it should probably work on individual breps as well, I'll add those overloads to RhinoCommon.

 

-----------------------------

 

Dim volume As Double = rhino.geometry.VolumeMassProperties.Compute(result(0))

 

This is wrong. VolumeMassProperties.Compute() does not return a single number. It returns a new instance of the VolumeMassProperties class, which contains the volume, but also the error, the centroids, the moments of inertia and so on and so forth.

 

Dim vp As VolumeMassProperties = VolumeMassProperties.Compute(result(0))

A = vp.Volume

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Ahh now its finally getting to me. Still trying to figure out how to interpret and apply the Rhino.Common tools. Thanks for the quick response.

 

Now I only need to figure out a way to do this for 1000+ objects without waiting too long :) Lets see what the rhino.common has to offer.

Hmm just when I thought I had it... I lost it again...

 

Now the issue is with the brep.closestPoint

 

Dim result As New list (Of Boolean)

Dim check As Boolean = False

For i As Integer = 0 To points.Count() - 1

check = False

For k As Integer = 0 To objs.Count() - 1


Dim closestPt As point3d = Nothing
Dim ci As ComponentIndex = Nothing
Dim s As Double = Nothing
Dim t As Double = Nothing
Dim normal As Vector3d = Nothing

If (objs(k).ClosestPoint(points(i), closestPoint, ci, s, t, maxDistance, normal)) Then

check = True
Exit For
End If

Next


result.Add(check)


Next

A = result

 

The result is : "Error: 'closestPoint' is not declared. It may be inaccessible due to its protection level. (line 104)"

 

What does this mean?


 

closestPoint vs. closestPt. You need to use the same name when declaring and using a variable :)

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

argh... feeling like your avatar now...

 

Thnx!

Works like a charm now. Compared to my previous contraption I got the calculation done in 54ms instead of 15.5 secs... Nice...

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