web analytics

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"
		arrPolylineVertices = Rhino.PolylineVertices (strPolyline)
		If  (IsPointInPolyLine(arrTestPt, arrPolylineVertices) = 1) Then
			Rhino.Print "the point you just picked lies inside the polyline"
			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)))



Categorised as: Generative design

One Comment

  1. Actually, there is already a native Rhinoscript method called
    Didn’t notice it until today, haha…

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

* Copy This Password *

* Type Or Paste Password Here *