Given a set of coordinates (x,y,z), we would like to obtain the index of the element where this point belongs.
How to do it:
As a first approach, my idea would be the following: We could add to the mesh an element-element connectivity map (which has not been implemented yet but is quite standard to have). Once this is done, a Dijkstra algorithm could be used to navigate between elements until finding the one containing the target coordinates. As a distance function, one could use the distance between the target coordinates and the baricenter of the elements (since all elements are convex, this would be an OK measure).
To do:
[x] Implement the element-element connectivity matrix into the mesh class.
[x] Implement a function returning the baricenter of an element.
[x] Implement the Dijkstra-like algorithm: Starting from a reduced number of elements (as spread as possible), add their neighbors to a list. The list is then ordered by distance and the first element is considered as new candidate. Repeat until found, checking if the point is in the element at each step.
Possible other options:
Have an array with all baricenters, and look for the minimum distance using one of the optimized c++ sorting libraries. There exists a possibility that the selected element is not the solution (the baricenter distance could fail) but one of the neighboring elements will be.
Given a set of coordinates (x,y,z), we would like to obtain the index of the element where this point belongs.
How to do it:
As a first approach, my idea would be the following: We could add to the mesh an element-element connectivity map (which has not been implemented yet but is quite standard to have). Once this is done, a Dijkstra algorithm could be used to navigate between elements until finding the one containing the target coordinates. As a distance function, one could use the distance between the target coordinates and the baricenter of the elements (since all elements are convex, this would be an OK measure).
To do:
Possible other options: