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) :
if type(interlist)==type(tuple()) :
else : # c0 c1 c2 are on the same line
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) :
if str(a)=='-1.#IND' : a=0
if str(c)=='-1.#IND' : c=0
rot=atan2( c, a )*(180/pi)
def writeVec(lenght,alpha,z=0) :
x=(lenght * sin(beta)) / sin(alpha+beta)
y=(lenght * sin(alpha)) / sin(alpha+beta)
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 :
it’s your shape
I edited the pointinpoly function, there was a call to another function, useless here.