Compute the distance of a point to the boundary

Hi all,

Recently, I am working on a problem which need to calculate the distance of all the interior points to the boundary. I use the following code:

bmesh = BoundaryMesh(mesh, "exterior")
bbtree = BoundingBoxTree()
bbtree.build(bmesh)
vertex_distance_to_boundary = MeshFunction("double", mesh, 0)
for v_idx in xrange(mesh.num_vertices()):
    v = Vertex(mesh, v_idx)
    _, distance = bbtree.compute_closest_entity(v.point())
    print distance
    vertex_distance_to_boundary[v_idx] = distance

It works well, but I am wondering how FEniCS computes the distance? What’s the method/algorithm used behind? I can not find any explanation here and there.

Thanks,
Leon

Do you mean the nearest distance to the exterior boundary? In which case consider computing the FEM approximation of the Eikonal equation.

1 Like

An Implementation of such an approximation can be found here (compatible with dolfin 2018.1.0) https://bitbucket.org/Epoxid/femorph/src/c7317791c8f00d70fe16d593344cb164a53cad9b/femorph/Legacy/SAD_MeshDeform.py?at=dokken%2Frestructuring

Thank you very much! That’s what I want. I tried to solve the Eikonal equation by myself, but it is unstable. Your provided algorithm is very stable. I also trying to find some references for the algorithm, but I can not find the one used in the link. Do you know some references of the Algorithms?

Thanks Again,

I seem to recall it is referenced in this paper .

The approximation is Also mentioned in this Preprint, But be careful as ive found several typos in it.

Thanks for the information. I also found these two papers.

Paper 2 introduced the equation (3.7) and cited the paper 1. But I can not find any clue in paper 1.

It seems it is a good algorithm, but no paper has provided an analysis or a detailed explanation.