Grasshopper

algorithmic modeling for Rhino

I am scripting in Grasshopper with VB and need to extract the intersection points of several polylines.

Do I need to convert the polylines to curves first (If so how do I do this as .GetNurbForm doesn't seem to work) or do is there a way to find the intersections directly?

Views: 1807

Replies to This Discussion

Well, since OnPolyLine isn't really a curve class, you won't be able to do much with it as an OnPolyLine unless you took care of the intersection yourself (which wouldn't necessarily be too complicated here). However, if you convert the polylines to a class that derives from OnCurve (such as OnPolyLineCurve) then you can use the IntersectCurve method that is exposed to OnCurve classes. Here's a quick run down...


'These constructors should work because OnPolyLine
'derives from ArrayOn3dPoint
Dim plCrv1 as New OnPolyLineCurve (polyLine1)
Dim plCrv2 as New OnPolyLineCurve (polyLiine2)

Dim intersectionEvents as New ArrayOnX_EVENT()

plCrv1.IntersectCurve (plCrv2, intersectionEvents, doc.AbsoluteTolerance)

'ToDo: Sort through intersection events...


One thing to note is that polylines created by GH are already PolyLineCurves, so you shouldn't have to "convert" them.
Thank you for your help..you are completely right on the lack of need to "convert" anything- I mistakenly was creating OnPolyLine instead of OnPolyLineCurve from my array of On3dPoint.

However, one further question... the IntersectCurve output doesn't seem to give me the intersection point, which is what I really need. Is there a way to extract that point?
That function outputs an array of OnX_Events, which will actually tell you more about the intersection than just a point. It carries the intersection type, which in almost all cases is going to be a point intersection, although there is a possibility of an overlap condition (one line being on top of another). It also carries the parameters of the intersections for both curves. There may be multiple intersections, so this information is stored as an array. Below is a very quick way to point from an intersection event. This doesn't really do any sorting or anything, which may be helpful in a more complex situation


'''continuing from previous example...
Dim intersectionPoints as New List (of On3dPoint)

If intersectionEvents.count > 0 Then
'there's at least one intersection
For i as integer = 0 to intersectionEvents.count-1
intersectionPoints.Add(plCrv1.PointAt(intersectionEvents(i).m_a(0))
Next
End If

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