This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

closest vertex to point

+5 votes

Given a Point p one can do

p1 = mesh.closest_cell(p) 

How can I find the closest vertex to a point?

asked Jun 25, 2013 by chaffra FEniCS User (1,830 points)
edited Jun 25, 2013 by Garth N. Wells

1 Answer

+1 vote
 
Best answer
min((p.distance(v.point()), v) for v in vertices(Cell(mesh, mesh.closest_cell(p))))[1]
answered Jun 26, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Jun 27, 2013 by Garth N. Wells

Hello, how would you update the answer given that closest_cell() does no longer exist? Thank you!

There are methods to do this in the BoundingBoxTree class.

...