So, I want to detect if a point lies exactly on the boundary of a trimesh object, and by that I mean that it lies on an edge of the surface. Allow me to present a toy example:
import numpy as np
import trimesh
# define geometry
mesh = trimesh.creation.capsule(4,4) # toy example
mesh.faces = mesh.faces[:3500] # "remove" some faces so that we do have a boundary
# get point in surface
point = np.array([4, -1,0])
footpoint, distance, triangle = [_[0] for _ in mesh.nearest.on_surface([point])] # footpoint is the point we want to see if it is exactly on the boundary
# get the faces that form the boundary
index = trimesh.grouping.group_rows(mesh.edges_sorted, require_count=1)
boundary_faces = mesh.faces[surface_trimesh.edges_face[np.sort(index)]]
The way of getting the boundary faces is straight ahead from this GitHub post To see that everything is working correctly, I show the information using Plotly as follows: fig1 shows the mesh, point and footpoint, and fig2 shows the triangles that form the boundary of the mesh, as well as both the point and footpoint.
import plotly.figure_factory as ff
import plotly.graph_objects as go
X, Y, Z = np.array(mesh.vertices).T
x,y,z = np.array([point, footpoint]).T
fig1 = go.Figure()
fig1 = ff.create_trisurf(x=X, y=Y, z=Z, simplices=mesh.faces)
fig1.add_scatter3d(x=x, y=y, z=z)
fig1.update_layout(scene=dict(aspectmode='data'))
fig1.show()
fig2 = go.Figure()
fig2 = ff.create_trisurf(x=X, y=Y, z=Z, simplices=boundary_faces)
fig2.add_scatter3d(x=x, y=y, z=z)
fig2.update_layout(scene=dict(aspectmode='data'))
fig2.show()
Likewise, boundary_edges = mesh.edges[index] returns an array of shape (N, 2) where each row is the edge of a boundary triangle that is actually on the boundary. Also, triangle has the index of the triangle footpoint lies on. So, how do I get the appropriate edge on boundary_edges? Because I am quite lost with the indexing and, also, I am not that sure boundary_edges works as I think.
Thank you all very much in advance, and if there is anything else I can do to clarify my question, please, let me know!!
