You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Checking for separating planes instead of relying on Jordan ray theorem, something like this:
@nb.njit(inline="always")defpoint_in_convex_polygon(p: Point, poly: FloatArray) ->bool:
"""Half-plane check."""positive=Falsenegative=Falselength=len(poly)
v0=as_point(poly[-1])
foriinrange (length):
v1=as_point(poly[i])
U=to_vector(p, v0)
W=to_vector(v0, v1)
ifcross_product(U, W) >0:
positive=Trueelse:
negative=Trueifpositiveandnegative:
returnFalsev0=v1returnTrue@nb.njit(inline="always")defpoint_in_convex_polygon_or_on_edge(p: Point, poly: FloatArray) ->bool:
"""Half-plane check."""positive=Falsenegative=Falselength=len(poly)
v0=as_point(poly[-1])
foriinrange(length):
v1=as_point(poly[i])
U=to_vector(p, v0)
V=to_vector(p, v1)
W=to_vector(v0, v1)
twice_area=abs(cross_product(U, V))
iftwice_area<TOLERANCE_ON_EDGE:
# Project the point onto W.W=to_vector(v0, v1)
ifW.x!=0.0:
t= (p.x-v0.x) /W.xelifW.y!=0.0:
t= (p.y-v0.y) /W.yelse:
# The vector has a length of zero. Skip.continueif0<=t<=1:
# Now it's on the edge.returnTrueifcross_product(U, W) >0:
positive=Trueelse:
negative=Trueifpositiveandnegative:
returnFalsev0=v1U=VreturnTrue
This seems to be approximately two times faster than the current check. However, it's obviously less robust (cannot deal with concave polygons). Annoyingly (and expectedly), it reports different results for edge cases such as a point located on a vertex.
Given only moderate speed-up and less robustness, it's probably best to stick to the current implementation (also given status quo bias...).
The text was updated successfully, but these errors were encountered:
Checking for separating planes instead of relying on Jordan ray theorem, something like this:
This seems to be approximately two times faster than the current check. However, it's obviously less robust (cannot deal with concave polygons). Annoyingly (and expectedly), it reports different results for edge cases such as a point located on a vertex.
Given only moderate speed-up and less robustness, it's probably best to stick to the current implementation (also given status quo bias...).
The text was updated successfully, but these errors were encountered: