the midpoint test won’t work (alone) in all cases, as you can have a part of a segment inside the poly and the other part outside.

ok I get it, your points are the verts of the poly itself. so you assume they are in the poly.

but the function above will return false if the point is on the perimeter (your case)

if 2 points A and B are (really) inside a poly, one can tell that if the segment [AB] do not cross any segment of the polygon, [AB] is completely inside :

no intersections (inside)

one intersection (goes outside)

in your case (it’s also mine for the city engine) I use one of the 2 tricks :

either I enlarge the poly,

either I do the test with point slightly inside the poly :

rather than test this :

I test this :

so it’s like the common case.

the thing is to find the correct location for the 2 test points :

```
from Blender.Mathutils import *
def angleEnlarge(c0,c1,c2,w) :
c0=Vector(c0)
c1=Vector(c1)
c2=Vector(c2)
v0=c1-c0
v1=c2-c1
sz,rot=readVec(v0)
b=writeVec(w,rot-90)
b=b+c0
c=b+v0
sz,rot=readVec(v1)
d=writeVec(w,rot-90)
d=d+c1
e=d+v1
interlist=LineIntersect(b,c,d,e)
if type(interlist)==type(tuple()) :
return interlist[0]
else : # c0 c1 c2 are on the same line
return c
```

c0, c1 and c2 are 3 points of the poly, [x,y,z] or Vector[x,y,z]. z does not matter.

** must be listed in anti-clockwise order** otherwise you’ll obtain the outside points

w is the offseted point of c1. try 0.01 for example.

w positive is inside, w negative is outside (when anti-clockwise list)

here two other functions it needs to compute vectors :

```
def readVec(side) :
a=side[0]
c=side[1]
try :lenght=sqrt((a*a)+(c*c))
except :
if str(a)=='-1.#IND' : a=0
if str(c)=='-1.#IND' : c=0
lenght=0
rot=atan2( c, a )*(180/pi)
return lenght,rot
def writeVec(lenght,alpha,z=0) :
beta=radians((90-alpha))
alpha=radians(alpha)
x=(lenght * sin(beta)) / sin(alpha+beta)
y=(lenght * sin(alpha)) / sin(alpha+beta)
return Vector([x,y,z])
```

readVec takes a vector like [1,2,0] (x+1 and y+2) and returns a lenght and a degree

writeVec takes a lenght and a degree and returns a vector

I use these functions in oce, these one are a bit simplified but you can find them in /bin/primitives.py

it’s a bit tedious I know maybe there’s something better but I don’t find it.

you’ll also have to convert your poly as a list of verts coordinates like :

```
poly=[[0,0,0],[1,0,0],[1,1,0],[0.7,1,0],[0.5,1.3,0],[0.3,1,0],[0,1,0]]
```

it’s your shape

I edited the pointinpoly function, there was a call to another function, useless here.