I am using the trimesh library, to check this. It has mesh.contains for performing these checks. I am trying to truncate an array of lines using the mesh.contains, such that the new lines only contain the points from inside the mesh.
Although this works fine for in some cases, it fails in multiple other cases. I am attaching a few pictures, the blue is the truncated line and the red is the original line. The gray shaded region is the mesh. In one case, it is able to detect points outside and truncate properly. However, there are issues in case of outside regions that are sandwiched between the domains. The points are outside, but this function is unable to eliminate them.
The code chunk is given below:
# create an empty array to store truncated lines
truncated_arr = []
# loop over each line in the array
for line in arr:
new_line = []
# loop over each point in the line and check if it's inside the mesh
for point in line:
if ((mesh1.contains([point])) or (mesh2.contains([point])) or (mesh3.contains([point]))):
new_line.append(point)
# append the truncated line to the new array
if len(new_line) > 1:
truncated_arr.append(new_line)
I am looking for ideas to overcome this? Is there a way to make this algorithm detect points that are outside the domain but is sandwinched between two wings of the domain, as seen in the picture? Ideally I would want this library to work but unfortunately if it doesn't suggestions for others might also be helpful.
Thanks.