# Blender script: how to determine if a vertex from one 2D mesh is inside another?

Using the Blender API, what is the best way to find out if a vertex from one 2D mesh is inside another?

All I want is a simple yes/no is a point inside a mesh. But even something this fundamental is proving very vexing.

The script below selects wrong half the time, making it little better than flipping a coin:

# Function to find nearest vertex not inside another mesh
def find_nearest_vertex_not_inside_bm_b(intersection_point, bm_a, bvhtree_b):
nearest_vertex = None
min_distance = float('inf')

for v in bm_a.verts:
point = v.co
location, normal, index, distance = bvhtree_b.find_nearest(point)

if distance > 0:  # vertex is not inside bm_b
dist_to_intersection = (point.xy - intersection_point.xy).length
if dist_to_intersection < min_distance:
min_distance = dist_to_intersection
nearest_vertex = v

return nearest_vertex

#
#
def is_vertex_inside_mesh(vertex, bm, bvh_tree):
point = vertex.co.xy
polygon = [v.co.xy for v in bm.verts]
return is_point_in_polygon_2d(point, polygon)

#
#
def is_point_in_polygon_2d(point, polygon):
x, y = point.xy
n = len(polygon)
inside = False

p1x, p1y = polygon[0].xy
for i in range(n + 1):
p2x, p2y = polygon[i % n].xy
if y > min(p1y, p2y):
if y <= max(p1y, p2y):
if x <= max(p1x, p2x):
if p1y != p2y:
xinters = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x
if p1x == p2x or x <= xinters:
inside = not inside
p1x, p1y = p2x, p2y

return inside


Please and thank you for any help.