# Point in a poly?

Is there any built in methods for this, or does anyone have some full code for it please?

Currently i’ve got this which uses the Jordan curve theorem (ref):

``````
c=False
tot=len(v)
k=0
j=tot-1
while k&lt;tot:
if (
((v[k]&gt;y) != (v[j]&gt;y)) and
( x &lt; (v[j]-v[k]) * (y-v[k]<i>) / (v[j]-v[k][I]) + v[k][I]) ):
c= not c
</i>[/I][/I] j=k
k+=1
return c

x = 5 # 25
y = 5
verts=[(0,0),(0,10),(10,10),(10,0)]
print(pin(x, y, verts))

``````

Yes, the test is a square, but goes to show it’s weaknesses…

I’m just doing an implementation of a ray casting method using the odd-even rule, and probably a winding number method… Any comments on speed, or built in c/c++ functions, etc would be nice.

Cheers!

And here’s solution 1 from here

``````
def inpoly(x, y, v):
tot=len(v)
counter=0
k=1
xinters=0.0
p1=[]
p2=[]
p1=v
while k&lt;=tot:
p2=v[k%tot]
if y &gt; min(p1,p2):
if y &lt;= max(p1,p2):
if x &lt;= max(p1,p2):
if p1 != p2:
xinters = (y-p1) * (p2-p1) / (p2-p1) + p1
if (p1 == p2) or (x &lt;= xinters):
counter+=1
p1 = p2
k+=1

if counter % 2 == 0:
return False
else:
return True

x = 5
y = 5
v=[(0,0),(0,10),(10,10),(10,0)]
print(inpoly(x, y, v))

``````