Grasshopper

algorithmic modeling for Rhino

(file attached)
So I have a grid of lines and a sphere. I need to find out lines intersect the sphere. I know its just true/false stuff but I can't get around this error: "variable <name> is passed by reference before it has been assigned a value" and therefore all of the results are "true" (which I'm sure you can imagine is quite useless)

  Private Sub RunScript(ByVal gPts As List(Of Point3d), ByVal iLns As List(Of Curve), ByVal sp As Brep, ByRef A As Object) 
    Dim ptBL As New List (Of Boolean)
    Dim lAr() As curve = iLns.ToArray
    Dim i As New Int32
    For i = 0 To iLns.Count - 1
      Dim iLn() As Curve
      Dim iPt() As Point3d
      Dim tf As Boolean = rhino.Geometry.Intersect.Intersection.CurveBrep(lAr(i), sp, 0, iLn, iPt)
      ptBL.Add(tf)
    Next
    a = ptBL

All I'm looking for is a simple true or false

An alternative solution would be to add data to an empty branch of a data tree. After the brepCurveIntersect battery I have a list with plenty of empties. If I can add data to those empty trees that would also solve my problem. 

I am ultimately going to make a surface which is influenced by a few breps from lofting interpolated curves together. However, in order for the interpolated curves to render correctly I need the data trees intact and in order. Can anyone help?

Views: 2579

Attachments:

Replies to This Discussion

See attached. One script for generic Curve|Brep intersection tests, one specifically for (finite) Line|Sphere intersection.

The reason you're getting the "variable is passed by reference before it has been assigned a value" warning is because both iLn and iPt are null when you call the Intersection.CurveBrep() method. There's nothing wrong with this, they're actually supposed to be null, but VB doesn't know this. It merely points out that you are doing something potentially dangerous. To make the warning go away, specifically set these variables to null. This way you can put your foot down and tell VB to back the f*ck off and mind it's own business:

Dim iLn As Curve() = Nothing

The Intersection.CurveBrep() method does not return True or False based on whether it found any intersections. It returns True when it's happy with the intersections it came up with. If something went terribly wrong inside the intersector and the results cannot be trusted, False is returned.

To see whether there were any intersections, you should test to see whether iPt is empty. All the intersection points will be stored in this array, so if it's still Nothing when it comes out of the CurveBrep() method, there were no intersections.

--
David Rutten
david@mcneel.com
Seattle, WA
Attachments:
Thanks a million David, I used the True's and false's if then statement to add the intersection points in the data tree in order and it worked perfectly, but I do have a question...
In your 'if then' statement you have
If (rc) Then
If (pts Is Nothing) OrElse (pts.Length = 0) Then rc = False
End If

X.Add(rc)

Which has an 'if' within an 'if'. yet you only have to say 'end if' once... why?

thanks again
There's a shorthand notation for If statements. If you write something after Then on the same line, you do not need to close with End If. The following two are identical:

If (pts Is Nothing OrElse pts.Length = 0) Then rc = False

If (pts Is Nothing OrElse pts.Length = 0) Then
   rc = False
End If


--
David Rutten
david@mcneel.com
Seattle, WA

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service