rs.PointInPlanarClosedCurve() vs rg.Curve.Contains()

How can I get this script to run in Rhino common vs rhinoscriptsyntax?

rs.PointInPlanarClosedCurve(pts[i],Curve) returns True and False

but

rg.Curve.Contains(curve, pts[i], plane, 0.001) returns “Inside” and “Outside”

How do I change the logic in this to make the Rhino.Geometry work?
if boolean[i] == True:
ptIn.append(pts[i])
if boolean[i] == False:
ptIn.append(pts[i])

Should I be checking if “Inside” or “Outside” are in boolean first?

I am using the ghPython node in grasshopper.

import Rhino
import random

pts =
for i in range(0,4):
pt = Rhino.Geometry.Point3d(random.uniform(0,10), random.uniform(0,10), 0)
pts.append(pt)

boolean =
ptIn =
ptOut =

for i in range(len(pts)):
pt_in_or_not = Rhino.Geometry.Curve.Contains(curve, pts[i], plane, 0.001)
boolean.append(pt_in_or_not)

#Contains function returns "Inside" and "Outside" NOT True and False

if boolean[i] == True:
    ptIn.append(pts[i])
if boolean[i] == False:
    ptIn.append(pts[i])

ptIn_Out = ptIn
ptOut_Out = ptOut

Here is the code behind rs.PointInPlanarClosedCurve():

def PointInPlanarClosedCurve(point, curve, plane=None, tolerance=None):
    """Determines if a point is inside of a closed curve, on a closed curve, or
    outside of a closed curve
    Parameters:
      point (point|guid): text point
      curve (guid): identifier of a curve object
      plane (plane, optional): plane containing the closed curve and point. If omitted,
          the currently active construction plane is used
      tolerance (number, optional) it omitted, the document abosulte tolerance is used
    Returns:
      number: number identifying the result if successful
              0 = point is outside of the curve
              1 = point is inside of the curve
              2 = point in on the curve
    Example:
      import rhinoscriptsyntax as rs
      curve = rs.GetObject("Select a planar, closed curve", rs.filter.curve)
      if rs.IsCurveClosed(curve) and rs.IsCurvePlanar(curve):
          point = rs.GetPoint("Pick a point")
          if point:
              result = rs.PointInPlanarClosedCurve(point, curve)
              if result==0: print "The point is outside of the closed curve."
              elif result==1: print "The point is inside of the closed curve."
              else: print "The point is on the closed curve."
    See Also:
      PlanarClosedCurveContainment
      PlanarCurveCollision
    """
    point = rhutil.coerce3dpoint(point, True)
    curve = rhutil.coercecurve(curve, -1, True)
    if tolerance is None or tolerance<=0:
        tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    if plane:
        plane = rhutil.coerceplane(plane)
    else:
        plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
    rc = curve.Contains(point, plane, tolerance)
    if rc==Rhino.Geometry.PointContainment.Unset: raise Exception("Curve.Contains returned Unset")
    if rc==Rhino.Geometry.PointContainment.Outside: return 0
    if rc==Rhino.Geometry.PointContainment.Inside: return 1
    return 2

I might be biting off more than I can chew with trying to convert some rhinoscriptsyntax scripts into Rhino Common, but I am going to try. I hope I don’t bother this forum too much with my questions.

Thank you for the quick response.

Michael

1 Like

If you are posting code here try the following formatting to make it easier to read/copy:

```python (three "backticks" plus python)

<paste your entire code in here>

``` (three more "backticks")

1 Like

Will do, thanks

testing…

import Rhino
import random

pts = []
for i in range(0,4):
    pt = Rhino.Geometry.Point3d(random.uniform(0,10), random.uniform(0,10), 0)
    pts.append(pt)
    
boolean = []
ptIn = []
ptOut = []
1 Like

Looks good!