Determining if the point lies inside a closed polyline
Option Explicit Dim arrTestPt Dim strPolyline arrTestPt = Rhino.GetPoint ("pick a point") strPolyline = Rhino.GetObject ("pick a closed polyline", 4) If Rhino.IsCurveClosed (strPolyline) Then If Rhino.IsPointOnCurve (strPolyline, arrTestPt) Then Rhino.Print "the point you just picked lies on the polyline" Else arrPolylineVertices = Rhino.PolylineVertices (strPolyline) If (IsPointInPolyLine(arrTestPt, arrPolylineVertices) = 1) Then Rhino.Print "the point you just picked lies inside the polyline" Else Rhino.Print "the point you just picked lies outside the polyline" End If End If End If '----------------------------------------------------------------------------------------- ' polyX = array of X coordinates of polylinevertices ' polyY = array of Y coordinates of polylinevertices ' arrPt = Test Point '----------------------------------------------------------------------------------------- Function pnpoly(polyX,polyY,arrPt) Dim npol :npol = UBound(polyX) Dim i : i =0 Dim j : j = npol-1 Dim c : c = -1 Dim x : x = arrPt(0) Dim y : y = arrPt(1) Do While (i < npol) If ((polyY(i)=y) OR (polyY(j)=y)) Then If ((polyX(i)+(y-polyY(i))/(polyY(j)-polyY(i))*(polyX(j)-polyX(i)))
References
http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
http://alienryderflex.com/polygon/
Categorised as: Generative design
Actually, there is already a native Rhinoscript method called
PointInPlanarClosedCurve()
Didn’t notice it until today, haha…