BrunoLevy / geogram

a programming library with geometric algorithms
Other
1.83k stars 125 forks source link

public locate method #183

Open jaredmagnusson opened 2 hours ago

jaredmagnusson commented 2 hours ago

Hello! Is there a public method to determine which tetrahedron a given point resides in? Or a way to call Delaunay3D:locate directly? I'm looking to do some linear interpolation.

Some workarounds I see are:

  1. call nearest_vertex for some point P then call get_neighbors on that vertex to get the list of cells around point P. Then check each of those cells to determine if P is in them. this seems a little indirect and perhaps costly?
  2. create a new class to inherit from Delaunay3d and access the protected method locate that way
BrunoLevy commented 2 hours ago

Hello,

Yes, I should probably expose locate() to the public API, so the easiest way is to inherit and access the protected method as you suggested, but there is a little "gotcha": locate() needs the infinite tetrahedra (that connect all vertices of the convex hull to a virtual "vertex at infinity") for working (call set_keep_infinite(true)). If you do not want to keep the infinite tetrahedra, then it is possible to implement a locate() function but it requires a bit of work.

This is the reason why I did not let locate() in the public API.

jaredmagnusson commented 1 hour ago

This is good to know thank you. Is there a limitation to having keep_infinite enabled? The behavior of locate() returning -1 if a point lies outside the convex hull would be just fine