Hi @hosneyalaa
actually Matplotlib is not compatible with IP2 (maybe in the future with IPY3 + Ironclad ) you need to use CPython3 engine and install Matplotlib (it’s OOTB in Revit/Civil 2024)
Alternatively, you can use Ray tracing (compatible all Python Engine)
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Ray tracing
def ray_tracing_method(x,y,poly):
n = len(poly)
inside = False
p1x,p1y = poly[0]
for i in range(n+1):
p2x,p2y = poly[i % n]
if y > min(p1y,p2y):
if y <= max(p1y,p2y):
if x <= max(p1x,p2x):
if p1y != p2y:
xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x
if p1x == p2x or x <= xints:
inside = not inside
p1x,p1y = p2x,p2y
return inside
polycurve = IN[0]
input_pts = IN[1]
polygon = [(c.StartPoint.X, c.StartPoint.Y) for c in polycurve.Curves()]
insidepts = [p for p in input_pts if ray_tracing_method(p.X, p.Y, polygon)]
OUT = insidepts