generative modeling for Rhino
Hi there, I am very new to VB.NET scripting in grasshopper. I am stuck trying to do probably quite a simple thing - intersecting a line with a curve. I have two points C,D which define a line. I have a curve. Let's say they intersect in a point. Could anybody please write a short example code of how to do that? I am a little lost as in where to look for which commands, utilities etc. I was going through the forums and many of the posts are using an older version of the script? I am using rhino5 and the latest grasshopper. For example I use 'point3d' rather then 'onpoint' ... Would you recommend any download or site where i can browse for the script commands, classes etc?
This is what i have written so far, obviously it does not work:
Private Sub getintersectionA (ByVal C As point3d, ByVal D As point3d, ByVal Acurve As curve, ByRef intersectionA As Object)
Dim pointlist As New List (Of point3d)
Dim sideline As New polylinecurve (pointlist)
intersectionA = intersect.Intersection.CurveCurve(sideline, Acurve, 0, 0)
any help appreciated!
You'll need to convert your Line into a Curve first, as Intersect.Intersection.CurveCurve demands two curves.
intersectionA = intersect.Intersection.CurveCurve(new Rhino.Geometry.LineCurve(sideline), Acurve, 0, 0)
Thank you David for your reply.
So now I have something in the 'intersectionA' variable. How do I get the actual point out of it?
dim point as point3d = intersectionA does not work
dim point as point3d =intersection(0) does not work
you know what i mean?
The Intersection.CurveCurve() method returns a collection of intersection events, as two curves can have any number (zero, one, five, 1292) of intersections. You'll need to iterate over the intersection events and then for each one find the intersection point.
Also note that an intersection event is not a single point in space. Whenever two curves get close enough within tolerance, an intersection is assumed. There is therefore a separate point on curve A and another one on curve B.
Unfortunately the Code Editor I use for VB/C# scripts doesn't handle collections very well. I attached a file (VB script) which finds all the intersections between two curves and then returns the one that is closest to a test point.
Note that I only look at PointA, I ignore PointB and I also ignore curve overlaps events. You probably shouldn't.
Thank you David,
I'll have to get the latest build to open your file, apparently I am on 0.8.005, the latest download is 0.8.0062, although when trying to open your file I am getting a message it was saved in 0.9 version! I'll try with the latest download. Anyways, I was wondering if you could suggest any source where I could study these basica things of VB scripting as my questions could just go on...
I'm the developer of Grasshopper, therefore I typically use a version that hasn't been released yet, because as soon as I release 0.9.0001 I'll start working on (and with) 0.9.0002.
The files should open I think, although file forward compatibility is not one of my major goals.
There are of course books and web-based tutorials that talk about programming. I find that after not too long, you start to see the logic of the .NET OOP approach and you'll be able to figure out things as they come along. Any questions you can always post here or on the Rhino plug-ins newsgroup.